July 2012
Beginner to intermediate
342 pages
7h 27m
English
In order to deliver web content we need to make a URI available. This recipe walks us through the creation of an HTTP server that exposes routes to the user.
First, let's create our server file. If our main purpose is to expose server functionality, it's general practice to call the file server.js, which we could put in a new folder. It's also a good idea to install and use hotnode:
sudo npm -g install hotnode
hotnode server.js
Hotnode will conveniently auto-restart the server when we save changes.
In order to create the server we need the http module, so let's load it and use the http.createServer method:
var http = require('http'); http.createServer(function (request, response) { response.writeHead(200, ...Read now
Unlock full access