Another way to use absolute paths in js 'require'
consider following files structure:
...
▾ helpers/
timeHelper.js
timeHelper.test.js
▾ services/
handleSlackCommand.js
handleSlackCommand.test.js
index.js
package.json
...
in the package.json
add:
{
...
"dependencies": {
"dotenv": "^6.2.0",
"express": "^4.16.4",
...
"helpers": "file:helpers", <-- this line
},
}
now in the services/handleSlackCommand.js
I can use
const { whatever } = require('helpers/timeHelper');
instead of
const { whatever } = require('../helpers/timeHelper');
Tweet