O'Reilly logo

Node.js Essentials by Fabian Cook

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. Simple HTTP

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required