Overview
Makes your node modules first class, so:
// no more:
require('../../../awesomeModule')
// just:
require('awesomeModule').
How
It creates symlinks in ./node_modules for all the root directories in provided 'dirToLink' directory. Works on Mac, Linux and Windows.
Usage
Say you have project structure like
- server.js
- package.json
- backend
- models
- config
- controllers
This would allow to require any modules in './backend' directory directly.
npm install warp.firstclass
warp.firstclass './backend/'
Now if you somewhere deep below in you controllers, you can still do:
var db = require('models'); //instead of require('../../../models')
Execute automatically with npm install
add the following to package.json
scripts": { "preinstall": "warp.firstclass './backend/'"}
Troubleshooting
-
You get error " -bash: warp.firstclass: command not found "
node node_modules/warp.firstclass/bin/warp.firstclass.js './backend/'
-
If you get permissions errors when running
npm install
you might need to run it as a root user (admin). so:
Linux/Mac
sudo npm install --unsafe-perm
The --unsafe-perm option insures that it actually gets runned as root, because when you run npm install
as a root NPM tries to downgrade its privileges.
Windows
- open terminal as administrator
- run