Been a way from Node for a bit and am finding myself confused about something I thought I understood:
From outside a module that has an index.js, if I require('path/to/module'), that index.js is consulted for that module's exports.
Now, I've got a situation where I'm working within such a module, and am trying to make references relative to the module's own index.js:
// index.js
exports.find_tests = require('./lib/find_tests');
// test.js
require('./').find_tests // does not work
require('./index').find_tests // works
I thought the first variant (require('./').find_tests) would work. Am I totally off base? I've got no main entry in package.json.
require('./') yields is an empty object. What is it?require('./index') is exports in index.js.I'm not entirely sure on the "why" that it doesn't work as expected, but I can tell you that if you require('./.'), it will work as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With