Skip to content

Instantly share code, notes, and snippets.

@thoughtspeed7
Last active March 24, 2018 08:59
Show Gist options
  • Save thoughtspeed7/3ec4d0fcf8e3750988943a4360ba7512 to your computer and use it in GitHub Desktop.
Save thoughtspeed7/3ec4d0fcf8e3750988943a4360ba7512 to your computer and use it in GitHub Desktop.
Node.js Best Practices - Smarter Ways to Manage Config Files and Variables
// om namah shivay
// requires
const express = require('express');
// environment variables
process.env.NODE_ENV = 'development';
// uncomment below line to test this code against staging environment
// process.env.NODE_ENV = 'staging';
// config variables
const config = require('./config/config.js');
// module variables
const app = express();
app.get('/', (req, res) => {
res.json(global.gConfig);
});
app.listen(global.gConfig.node_port, () => {
console.log(`${global.gConfig.app_name} listening on port ${global.gConfig.node_port}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment