config.js files with Node

When you are publishing source code on platforms such as GitHub you want to be extra sure to be vigilant about security. One mistake that people make is to publish source code that includes usernames, passwords, keys, and other sensitive data which can quickly become problematic.

One way to avoid doing this is to use an external file which contains your sensitive data and not include that in any repositories (don't add it to your project in git).

Here is such a file called config.js

var config = {
	username: “username”,
	password: “password
}

module.exports = config
You can include this file in any node script with require:
var config = require('./config.js');
and then use the data defined in it where you need in your source code:
someFunctionThatRequiresPassword(config.username, config.password);