Node Tip: require() JSON files

If you didn’t already know this, it may come in handy. You can use Node’s require() function to require JSON files. It will return a hash. Just like require() always does, it will cache the file, and only load it once (no matter how many files you require it from).

Useful for config files.

var config = require('../config.json');

The file extension is optional, like always.

var config = require('../config');


Leave a Reply