UNPKG

warp.firstclass

Version:

Allows to access all your modules directly like: require('moduleName') by creating symlinks

64 lines (36 loc) 1.51 kB
## Overview Makes your node modules first class, so: // no more: require('../../../awesomeModule') // just: require('awesomeModule'). ## How It creates [symlinks](https://en.wikipedia.org/wiki/Symbolic_link) 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 1. You get error " -bash: warp.firstclass: command not found " node node_modules/warp.firstclass/bin/warp.firstclass.js './backend/' 2. 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](https://docs.npmjs.com/misc/config#unsafe-perm) 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