Use symlinks to avoid require 'hell'

I was reading the documentation for Facebook's Jest the other day and I noticed they suggest keeping your tests in an ugly test folder mainly so you don't need to have ridiculous require statements such as require('../../../../path/to/my/thing'). Well I am here to tell you there is an easier way.

All you need to do is to use a symlink to your folder in your npm ./node_modules and you can access your code pathed from anywhere. The only consideration is that you will have to ensure that your source folders don't use conflicting namespaces with the node modules you use.

There is even a cute little npm module to help you do it:

npm install link-package --save-dev

Rudi Yardley

Read more posts by this author.