Created
September 28, 2018 11:49
-
-
Save billchurch/53d535bc9ac34a7acf1ef4ac9a65769b to your computer and use it in GitHub Desktop.
HTTP echo server in node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.