Reputation: 34630
I have the following structure
|-src
|--test.js
|-spec
|--test_spec.js
I was wondering is there a way to include the src directory to the require path? I am trying to do the following in test_spec.js
require('test');
Instead of doing:
require('../src/test.js');
Upvotes: 1
Views: 681
Reputation: 18205
If you have a package.json
file you can require the directory where the file is and it will require the "main" file specified in it.
{
"main": "src/text.js"
}
Upvotes: 1
Reputation: 10843
You need to add src
to the NODE_PATH
environment variable.
export NODE_PATH=/path/to/src
Upvotes: 1