8th May, 2014

Storing NodeJS app config in environment

Storing application config in the environment variables helps separate development, testing and production configuration.

I've been using dotenv to store my local development settings in a .env file (which I don't copy to production)

Simply put

require('dotenv').load();

at the top of your app.js file, then create a .env file with

KEY=VALUE_PAIRS

like so.

Now KEY is accessable in your application using process.env.KEY

 

Add Comment

The opinions expressed here are my own and not those of my employer.