Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

olalonde/better-require

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPM version

Augments require() with support for multiple file formats.

Supported file formats

... which return a JSON object:

... which return a Javascript module:

... work in progress:

  • dynamic libraries
  • ruby
  • python

Behind the scenes, this module adds handlers to require.extensions.

Install

npm install better-require

Usage

/**
 * @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);

Example

Enable support for all file types:

require('better-require')();

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

Enable support for only a subset of 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);

Dependencies

Reference

http://nodejs.org/api/all.html#all_require_extensions

About

Augments require() with support for multiple file formats. Node.js / NPM package

Resources

License

Stars

Watchers

Forks

Packages

No packages published