Let's use Node Foreman to keep track of our environment variables! :balloon: :balloon: :crystal_ball:
A few notes:
Install globally to your machine using npm install -g foreman
Create a file called .env in your root folder. It's gitignored so it won't be sent with your PR.
Store any variables in your .env that you want 'process.env' to know about.
Delete your config.js, you won't be needing it anymore.
For example, since our project currently uses:
var consumer_key = process.env.CONSUMER_KEY;
var consumer_secret = process.env.CONSUMER_SECRET;
var access_token_key = process.env.ACCESS_TOKEN_KEY;
var access_token_secret = process.env.ACCESS_TOKEN_SECRET;
Node Foreman needs configuration in both Procfile and package.json to load vars. Since our Procfile specifies nodemon make sure you have nodemon installed locally. Our package.json is set to run nf start when you run node start, so to start the server/load the vars simply do:
$ npm start
> trendr@1.0.0 start /Users/psoshnin/Desktop/makersquare/greenfield/trendr-PERSONAL/trendr
> nf start
[OKAY] Loaded ENV .env File as KEY=VALUE Format
[OKAY] Trimming display Output to 96 Columns
3:22:02 PM web.1 | [nodemon] 1.8.1
3:22:02 PM web.1 | [nodemon] to restart at any time, enter `rs`
3:22:02 PM web.1 | [nodemon] watching: *.*
3:22:02 PM web.1 | [nodemon] starting `node app.js`
3:22:02 PM web.1 | Listening on: 5000
Let's use Node Foreman to keep track of our environment variables! :balloon: :balloon: :crystal_ball:
A few notes:
npm install -g foreman
.env
in your root folder. It's gitignored so it won't be sent with your PR..env
that you want 'process.env' to know about.For example, since our project currently uses:
In your
.env
file you want to have the following:Node Foreman needs configuration in both Procfile and package.json to load vars. Since our Procfile specifies
nodemon
make sure you havenodemon
installed locally. Ourpackage.json
is set to runnf start
when you runnode start
, so to start the server/load the vars simply do:Make sure to also use
localhost:5000
now :)