Setting up a config file for our app

Currently, our app runs off of whatever is in the app.js file. If you want to change how the application runs, you will need to edit app.js. This is not very maintainable. As a simple example, what if our cookie secret changes? What happens when we only update one of the references to the cookie secret? Let's say our app grows and the secret is referenced in two other middleware. This will create a lot of pain and waste time tracking down weird bugs in the code. What we need is a config file to store all the application's settings.

The first thing is to create a file named config.js in the root of our app and add this to the file:

var config = { port: 3000, secret: 'secret', redisUrl: 'redis://localhost', routes: ...

Get Building Scalable Apps with Redis 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.