really easy to use config object, extends with underscore
easy to use config object for your node.js app
npm install git+https://github.com/dhigginbotham/simple-conf --save
Step 2) view
/examples/config.coffee (or copy and paste to your app)
Step 3) require the config.coffee folder inside your app somewhere and
simple-conf is set to look for a couple environment vars by default, although, if you don't want to set these it will set some defaults instead..
process.env.NODE_PASS, this will set your initial seed admin password and keep this sensitive stuff
out of your repo. defaults to:
process.env.MONGO_DB_STRING, this will link up your mongodb url, good for production and public repos
I don't want to set these up! Oh, that's cool too -- it's not going to break, it's just there to help.
I've included a couple helpers that I use on my apps and find helpful -- maybe you will too?
extended - requires
req good for middleware, or schema stuff that has access to req, adds:
ip = req.headers["x-forwarded-for"] or req.connection.remoteAddress
user = if req.user? then req.user.username else "anonymous"
engine = req.protocol + "://" + req.get('host')
folders - requires
function (err, path)
.placeholderfiles and whatnot
colors - no requirements
redoutputs red font color to stdout
cyanoutputs cyan font color to stdout
resetresets font color to stdout
Config = require ".."fs = require "fs"path = require "path"env = processenvNODE_ENVport = if env == "production" then processenvport else 3000host = if env == "development" then ":"production = env == "production"development = env == "development"config =api:github:username: "dhigginbotham"coderbits:username: "dhz"app:title: "example-app"initials: "xpl"port: porthost: hostserverStart: "Starting up your express engines"paths:uploads: pathjoin __dirname"..""public""uploads"views: pathjoin __dirname"..""views"assets: pathjoin __dirname"..""public"seed:init: if production == true then false else truedebug:mongo: if production == true then false else falseconf = configif confdebugconfig == true then consolelog confmodule.exports = conf
note - defaults are now optional, ex:
new Config object, false renders a more modular config for mountable apps.
@app =@apptitle = "Default-config-build"@appinitials = "dcb"@appport = processenvport || 3000@apphost = ""@appserverStart = "Starting express server "@db =@dbpath = ""@dburl = processenvMONGO_DB_STRING || "mongodb://localhost/"@sesh =@seshkey = ".id"@seshsecret = _secret@seshmaxAge = 60 * 60 * 1000@seed =@seedinit = false@seedfolders = true@users =@usersroles = 'user''admin''editor''commenter'@userssignupEnabled = true@debug =@debugoverride = falseif opts? then _extend @optsif @seedinit == true@seeduser =@seeduser.username = "admin"@seeduser.password = "@dminPassw0rd"@seeduser.admin = firstname.lastname@example.org = "admin"@seeduser.email = "email@example.com"@seeduser.ip = "admin.ipv6"@
The MIT License (MIT)Copyright (c) 2013 David HigginbothamPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE.