jimmycuadra/bang — Issue #4: Cannot require .json with older node
Author: oylenshpeegul
Created: 2011-12-17 17:08:39+00:00
State: open

I am using the node supplied by Ubuntu 11.10

```
tim@spiff:~$ node -v
v0.4.9
```

which doesn't like bang

```

tim@spiff:~$ bang apples oranges

/home/tim/.node_libraries/.npm/bang/1.0.0/package/package.json:2
"author": "Jimmy Cuadra (http://jimmycuadra.com/)",
^

node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
SyntaxError: Unexpected token :
at Module._compile (module.js:397:25)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at require (module.js:346:19)
at Object. (/home/tim/.node_libraries/.npm/bang/1.0.0/package/lib/cli.js:11:13)
at Object. (/home/tim/.node_libraries/.npm/bang/1.0.0/package/lib/cli.js:72:4)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
```

[The node docs](http://nodejs.org/docs/v0.6.6/api/modules.html#module.require) say

> .js files are interpreted as JavaScript text files, and .json files are parsed as JSON text files.

but [I don't think that was true until recently](https://github.com/joyent/node/issues/1357). Anyway, to get bang to work I added

```
require.extensions[".json"] = function (m) {
m.exports = JSON.parse(fs.readFileSync(m.filename));
};
```

to the cli.js file before the

```
package = require("../package.json");
```

Now bang seems to work as advertised

```
tim@spiff:~/bang$ cake spec
------------ Saturday, December 17, 2011 11:40:16 AM ------------
Started
...........

Finished in 0.008 seconds
11 tests, 11 assertions, 0 failures
```

Sorry, I didn't make a pull request because I didn't know if this will screw up newer versions of node or not.