$ npm install better-require
Augments require() with support for multiple file formats.
... which return a JSON represenation:
... which return a Javascript module:
Behind the scenes, this module adds handlers to require.extensions.
npm install better-require
/**
* @param {String} optional - formats is a white space separated list of formats you would like require() to support.
*/
// support all available extensions
require('better-require')();
// support a subset of extensions
require('better-require')(formats);
require('better-require')('json');
var config = require('./config.json');
console.log(config);
Enable support for mutliple file types:
require('better-require')('json yaml xml');
// we can now require .xml, .yaml and .xml files!
var config = require('./config.yaml');
console.log(config);
http://nodejs.org/api/all.html#all_require_extensions
© 2010 - cnpmjs.org x YWFE | Home | YWFE