- This repo is an example express.js app with electrode-confippet module fully integrated
- The step-by-step instructions on building it from scratch can be found below
electrode-confippet is a versatile utility for managing your NodeJS application configuration. Its goal is customization and extensibility, but offers a preset config out of the box.
- This app was scaffolded using yeoman and express-generator
- First, install
yeoman
andexpress-generator
:
npm install -g yo
npm install -g express-generator
- Scaffold a new app using
yeoman
:
express expressApp
cd expressApp
npm install
- At this point, you should be able to run the server locally:
NODE_ENV=development npm start
npm install electrode-confippet --save
- Create the config folder:
mkdir config
cd config
- Add the following config files:
config
|_ default.json
|_ development.json
|_ production.json
- Add your configuration settings
- Update the
config/default.json
to have the following settings:
{
"server": {
"viewCache": false,
"xPoweredBy": true,
"port": 3000
}
}
- Update the
config/development.json
to have the following settings:
{
"server": {
"viewCache": false,
"xPoweredBy": true,
"port": 4000
}
}
- The above settings disable view cache, enable x-powered-by header and run the server in port 4000
- Update the
config/production.json
to have the following settings:
{
"server": {
"viewCache": true,
"xPoweredBy": false,
"port": 8000
}
}
- The above settings enable view cache, disable x-powered-by header and run the server in port 8000
- Keys that exist in the
config/default.json
that are also in the other environment configs will be replaced by the environment specific versions
- Add the following to app.js:
const config = require("electrode-confippet").config;
app.set("view cache", config.server.viewCache);
app.set("x-powered-by", config.server.xPoweredBy);
app.listen(config.server.port);
- Start the express app in
development
environment:
NODE_ENV=development npm start
- Start the express app in
production
environment:
NODE_ENV=production npm start
- Running in the selected environment should load the appropriate configuration settings
Built with ❤️ by Team Electrode @WalmartLabs.