-
-
Save florianbachmann/7372133 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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