Skip to content

Instantly share code, notes, and snippets.

@efpapado
Created November 23, 2018 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efpapado/d0abe72fd7d42e64e38b645bb7d8aab9 to your computer and use it in GitHub Desktop.
Save efpapado/d0abe72fd7d42e64e38b645bb7d8aab9 to your computer and use it in GitHub Desktop.
nodejs server that echoes the request
const http = require("http");
const querystring = require('querystring');
const hostname = "0.0.0.0";
const port = 3000;
const server = http.createServer((req, res) => {
console.log(`\n${req.method} ${req.url}`);
console.log(req.headers);
req.on("data", function(chunk) {
// console.log("BODY: " + chunk);
const data = chunk.toString();
const splitted = data.split('&');
for (let i=0; i<splitted.length; i++) {
let paramRaw = splitted[i];
let paramSplitted = paramRaw.split('=');
console.log(paramSplitted[0] + ' => ' + paramSplitted[1]);
}
});
res.statusCode = 200;
res.setHeader("Content-Type", "text/plain");
res.end("Hello World\n");
});
server.listen(port, hostname, () => {
console.log(`Server running at http://localhost:${port}/`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment