Server.js – where it all begins

Whenever you write a Node app, you always need to start somewhere. The typical convention while building servers with Node is that you have a single server.js file located within the root of your project. This file will boot up the server and start the whole process. In our case, this is the file that will create the HTTP server and listen for all HTTP events, which is ultimately the point of our entire application.

We are going to keep our server.js pretty lean so that its contents are very self-explanatory. Any major logic that is going to be executed within this file will actually be defered to external modules hosted within other files.

Before we can do anything within server.js, we need to require a few modules ...

Get Web Development with MongoDB and Node.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.