Skip to content

Instantly share code, notes, and snippets.

@tamg
Last active March 12, 2017 20:30
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 tamg/14fa443d31a2c723aaa483df20d6cd92 to your computer and use it in GitHub Desktop.
Save tamg/14fa443d31a2c723aaa483df20d6cd92 to your computer and use it in GitHub Desktop.
var http = require ('http');
//createServer takes a callback function, which gets invoked when a request occurs
//the callback function takes in request and response as parameters
//request (req) represents whats incoming
//response (res) represents the response we are building
http.createServer(function(req, res) {
//build the HTTP response
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World');
}).listen(1337, '127.0.0.1' );//listen at port 1337 on the localhost
//we can now go to the browser at the localhost:1337 address and send a req
//we then get a 'Hello World' response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment