Skip to content

Instantly share code, notes, and snippets.

@alvarow
Created August 17, 2016 20:38
Show Gist options
  • Save alvarow/08bea221c4ae9599d1711dab5ab98278 to your computer and use it in GitHub Desktop.
Save alvarow/08bea221c4ae9599d1711dab5ab98278 to your computer and use it in GitHub Desktop.
Simple HTTP Server in node.js
var http = require('http');
//Lets define a port we want to listen to
const PORT=8080;
//We need a function which handles requests and send response
function handleRequest(request, response){
response.writeHead(200);
response.end('It Works!! Path Hit: ' + request.url);
console.log('It Works!! Path Hit: ' + request.url);
}
var server = http.createServer(handleRequest);
server.listen(PORT, function(){
//Callback triggered when server is successfully listening
console.log("Server listening on: http://localhost:%s", PORT);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment