Skip to content

Instantly share code, notes, and snippets.

@florianbachmann
Forked from asciidisco/nodestuff.js
Created November 8, 2013 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save florianbachmann/7372133 to your computer and use it in GitHub Desktop.
Save florianbachmann/7372133 to your computer and use it in GitHub Desktop.
// config.js
module.exports = {
dev: {
dbname: 'foo',
host: '127.0.0.1',
pass: 'bar',
port: 1223
},
prod: {
dbname: 'baz',
host: '127.0.0.2',
pass: 'bam',
port: 1225
}
};
// db.js
module.exports = function (options) {
var DB = {
connection: null,
connect: function (options) {
if (this.connection) {
return this.connection;
}
this.connection = new Whatever(options);
return this.connection;
}
};
return DB.connect(options);
};
// in der "app.js"
var config = require('./config.js')[process.env.NODE_ENV];
var db = require('./db.js')(config);
db.query('Select whatever from wherever');
// programm dann so starten
node index.js NODE_ENV=dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment