Now that we have understood the basics, we can move on to something a bit more useful. In this chapter, we will look at creating an HTTP server and routing requests. While working with Node.js you will come across HTTP very often, as server side scripting is one of the common uses of Node.js.
Node.js comes with a built in HTTP server; all you need to do is require the included
http package and create a server. You can read more about the package at https://nodejs.org/api/http.html.
var Http = require( 'http' ); var server = Http.createServer( );
This will create your very own HTTP server that is ready to roll. In this state, though, it won't be listening for any requests. We can start listening on any port or socket we wish, ...