naked-json-require
Single function to "require" json file that lacks an extension
Last updated 5 years ago by danmactough .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install naked-json-require 
SYNC missed versions from official npm registry.

naked-json-require

Single function to "require" json file that lacks an extension

Usage

var json = require("naked-json-require");
var config = json("./path/to/some/json");

Why?

Generally, you can simply require any json file. But in node, if you try to do that with a json file that doesn't have a .json file extension, it will fail with the error:

SyntaxError: Unexpected token :

This is because the node module loader assumes that a file without an extension is a .js file, and tries to use the .js module loader. See: https://github.com/nodejs/node/blob/master/lib/module.js#L354

Current Tags

  • 1.0.1                                ...           latest (5 years ago)

2 Versions

  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (0)
None
Dev Dependencies (0)
None

Copyright 2014 - 2016 © taobao.org |