I use the Express Middleware concept for this, and it gives me good flexibility to manage files.
I am writing a detailed answer that includes how I use the configuration options in app.js to connect to the database.
So, my application structure looks something like this: 
How do I connect to the database? (I am using MongoDB, mongoose - ORM, npm install mongoose)
var config = require('./config/config'); var mongoose = require("mongoose"); var connect = function(){ var options = { server: { socketOptions:{ keepAlive : 1 } } }; mongoose.connect(config.db,options); }; connect();
in the config folder, I also have the "env" folder, which stores environment-related configurations in separate files, such as development.js, test.js, production.js
Now, as the name suggests, development.js stores configuration parameters related to my development environment, and the same applies to the testing and production cases. Now, if you want, you can have more configuration settings, such as staging, etc.
project-name / config / config.js
var path = require("path"); var extend = require("util")._extend; var development = require("./env/development"); var test = require("./env/test"); var production = require("./env/production"); var defaults = { root: path.normalize(__dirname + '/..') }; module.exports = { development: extend(development,defaults), test: extend(test,defaults), production: extend(production,defaults) }[process.env.NODE_ENV || "development"]
project-name / config / env / test.js
module.exports = { db: 'mongodb://localhost/mongoExpress_test' };
Now you can make it even more descriptive by breaking the URL, username, password, port, database, host name.
For more information, see my repo , where you can find this implementation, because now in all my projects I use the same configuration.
If you're more interested, check out Mean.js and Mean.io , they have some better ways to manage all of these things. If you are a beginner, I would recommend to keep it simple and achieve success, as soon as you feel comfortable, you can do the magic yourself. Greetings