Creating the Node.js server
The first step in developing the notes web application is coding the HTTP server that will serve the clients' requests, so we're going to start with the app.js
file.
The HTTP server relies on the Express.js module, so we first need to import the module and all other modules that will be used in the app.
Take a look at the following code:
var express = require('express'), app = express(), server = require('http').createServer(app), io = require('socket.io')(server), path = require('path'), bodyParser = require('body-parser'), model = require('./models/rethinkdb');
These seven lines actually do quite a bit of work! Let's go through them line by line.
The first line imports the Express.js module and makes it accessible through the express
variable so that we can use it in the script.
Line number two creates a new instance of an Express.js app, while line three imports the http
module and uses the app
variable to create an instance of an HTTP server.
Line number four imports...