npm.io
1.0.1 • Published 10 years ago

naked-json-require

Licence
MIT
Version
1.0.1
Deps
0
Vulns
0
Weekly
0
Stars
1

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

Keywords