Creating the app.js file

As we have already seen in previous chapters, the basis of all Node.js applications is the file where we set up all the dependencies and instantiate the application. In this case, we use the app.js file, but you can use any name.

Create a file called app.js and add the following code:

 // Node dependencies var express = require('express'); var path = require('path'); var favicon = require('serve-favicon'); var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); // Setup application routes var routes = require('./routes/index'); // Create a Express application var app = express(); // Defining the env variable process for development var env = process.env.NODE_ENV ...

Get Node.js 6.x Blueprints 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.