Skip to content

Instantly share code, notes, and snippets.

@tamg
Last active Mar 12, 2017
Embed
What would you like to do?
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