Sails.js Environment Config Variables
So Sails.js way of handling environment variables is horrifying.
Everything in config/local.js
and config/env
sort of do their job, but it’s not enough for environment variables.
What we really need is a place to store all of our config variables regardless if we are in a development, testing, or production environment. The answer is simple: use dotenv. This will load a .env
file or look for environment variables on the machine.
Start by pulling it into the Sails.js project and following the dotenv docs:
Then require dotenv in app.js
and load the .env
file:
Create a .env
and put some vars in it:
Now you can access those environment variables anywhere in the app (probably in some config/
files):