Skip to content

Instantly share code, notes, and snippets.

@HussainArif12
Last active April 22, 2020 11:10
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 HussainArif12/1c8664cb262d0e3569aa00cf98aa7b89 to your computer and use it in GitHub Desktop.
Save HussainArif12/1c8664cb262d0e3569aa00cf98aa7b89 to your computer and use it in GitHub Desktop.
const http = require("http");
const port = 3000
const Server = http.createServer((request, response) => {
if (request.method == 'POST') {
let buff = '' //buffer variable to save response
request.on('data', function (chunk) {
buff += chunk; //concat each newline to the buff variable
})
request.on('end', function () {
console.log('Body' + buff); //print out variable content
response.end("Body accepted" );
})
}
else {
response.writeHead(200, { 'Content-Type': 'text/plain' })
response.end('Hello');
}
})
.listen(port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment