better-require
require('better-require')('json yaml') lets you load JSON and YAML files using require syntax. For example: var config = require('./config.json'); Extensions available are: json, yaml.
Last updated 13 years ago by olalonde .
BSD · Repository · Bugs · Original npm · Tarball · package.json
$ npm install better-require 
SYNC missed versions from official npm registry.

Augments require() with support for multiple file formats.

Supported file formats

... which return a JSON representation:

... 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

Current Tags

  • 0.0.3                                ...           latest (13 years ago)

3 Versions

  • 0.0.3                                ...           13 years ago
  • 0.0.2                                ...           14 years ago
  • 0.0.1                                ...           14 years ago
Maintainers (1)
Downloads
Total 8
Today 0
This Week 0
This Month 4
Last Day 0
Last Week 0
Last Month 0
Dev Dependencies (3)

© 2010 - cnpmjs.org x YWFE | Home | YWFE