joyent/node — Issue #2174: require() json with and without extension
Author: gabipetrovay
Created: 2011-11-23 21:23:29+00:00
State: open

I have my ```app.js```:

```var items = require('./items')
console.log(items.id);```

and my ```items.json``` in the same directory:

```{ "id": 1 }```

I get:

node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module './items'
at Function._resolveFilename (module.js:317:11)
at Function._load (module.js:262:25)
at require (module.js:346:19)
at Object. (/home/gabriel/test/app.js:1:75)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at Array. (module.js:421:10)
at EventEmitter._tickCallback (node.js:126:26)

and here: http://nodejs.org/docs/v0.6.2/api/modules.html#file_Modules
I read that:
"If the exact filename is not found, then node will attempt to load the required filename with the added extension of .js, .json, and then .node."

What am I doing wrong?

If I also use the ```.json``` extension I don't get the error but I get an empty json: ```{}```

What is wrong here?

(Looks like I'm doing something totally wrong here.)

Thanks!