config/config.js
var env = process.env.NODE_ENV || 'development'; // for heroku deploy
if (env === 'development' || env === 'test') {
var config = require('./config.json');
var envConfig = config[env];
Object.keys(envConfig).forEach((key) => {
// loops through the env Object to copy the setting values from config.json to process.env
process.env[key] = envConfig[key]
});
}
config/config.json
{
"test": {
"PORT": 3000,
"MONGODB_URI": "mongodb://localhost:27017/ResuMakerTest",
"JWT_SECRET": "qwertyuihjkljklopIdonthavetorememberthis"
},
"development": {
"PORT": 3000,
"MONGODB_URI": "mongodb://localhost:27017/ResuMaker",
"JWT_SECRET": "qwertyuiop123456thisisrandom"
}
}
However, when deploying to Heroku, the JWT secret have to be set by Heroku CLI:
heroku config:set JWT_SECRET=mysecretvalue
We can check if the JWT_SECRET has been properly set up by running heroku config and view all variables.