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 7 years ago by olalonde .
BSD · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install better-require 
SYNC missed versions from official npm registry.

Adds file formats supported by require(). Will always return a JSON representation.

Supported file types are: json, yaml, csv, xml, ini.

Install

npm install better-require

Example

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);

Dependencies

Reference

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

Current Tags

  • 0.0.3                                ...           latest (7 years ago)

3 Versions

  • 0.0.3                                ...           7 years ago
  • 0.0.2                                ...           8 years ago
  • 0.0.1                                ...           8 years ago

Copyright 2014 - 2017 © taobao.org |