Skip to content

Instantly share code, notes, and snippets.

@w7089
Created January 10, 2019 12:25
Embed
What would you like to do?
httpServer.js
server = require('http').createServer()
const fs = require('fs');
server.on('request', (req, res) => {
switch (req.url) {
case '/home':
case '/about':
res.writeHead(200, {'content-type' : 'text/plain'})
res.end(fs.readFileSync(`.${req.url}.html`));
case '/':
res.writeHead(301, {'Location' : '/home'})
res.end()
break
default:
}
// res.write('Hello world\n')
// // req: req.IncomingMessage
// // res: http.ServerResponse
// setTimeout(function() {
// res.write('another hello\n')
// }, 2000)
// setTimeout(function() {
// res.write('2 another hello\n')
// }, 2000)
})
server.listen(8000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment