O'Reilly logo

Building Scalable Apps with Redis and Node.js by Joshua Johanan

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

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

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