Skip to content

Instantly share code, notes, and snippets.

@naholyr naholyr/index.js
Created May 4, 2016

Embed
What would you like to do?
Node config module
"use strict";
const { readFileSync } = require("fs")
const { parse } = require("json5")
const { merge } = require("lodash")
module.exports = merge({},
// Global defaults
requireConfig("defaults"),
// Environment defaults
requireConfig(process.env.NODE_ENV || "production"),
// Local configuration
requireConfig("local"),
// Environement variable overrides
{
port: process.env.PORT
}
);
function requireConfig (file) {
try {
return parse(readFileSync(__dirname + "/" + file + ".json"));
} catch (e) {
console.warn('WARN: ignored config file "%s.json": %s', file, e.message); // eslint-disable-line no-console
return {};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.