Skip to content

Instantly share code, notes, and snippets.

@billchurch
Created September 28, 2018 11:49
Show Gist options
  • Save billchurch/53d535bc9ac34a7acf1ef4ac9a65769b to your computer and use it in GitHub Desktop.
Save billchurch/53d535bc9ac34a7acf1ef4ac9a65769b to your computer and use it in GitHub Desktop.
HTTP echo server in node
const http = require('http')
const server = http.createServer((req, res) => {
let response = `URL(${req.url.length}): ${req.url}\r\nHeaders: ${JSON.stringify(req.headers)}\r\n\r\n`
res.end(response)
console.log(response)
})
server.on('clientError', (err, socket) => {
socket.end('HTTP/1.1 400 Bad Request\r\n\r\n')
})
server.listen(8081)
@billchurch
Copy link
Author

Just a dumb HTTP server that will listen on port 8081 and respond back with URL / URL Length and headers as well as output to console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment