Let's say you're writing a NodeJS application and you've created a library or module that you want to use in different places throughout your app. You don't want to register it with NPM because it isn't useful for anyone else since it's specific to your app. You also don't want to throw it in your node_modules folder because you need to track changes in git and you have the node_modules folder included in your .gitignore file.

What most people do is require that code using a relative path:

var my_module = require('../../lib/my_module.js');  

The path changes as you start requiring the module in different sections of your application. Then you move a file around and realize you have missing dependencies because you forgot to update the paths.

There's an easy fix to this problem.

In your package.json file, you can add a property in the scripts section called postinstall that runs a bit of code after npm install is run. Add the following postinstall code to create a symlink to a folder in the root of your project (in the code below I use a directory named lib).

  "name": "My_Application",
  "scripts": {
    "postinstall": "cd node_modules && ln -sf ../lib/ lib",

When I clone my project I just run npm install and the symlink will be created for me.

Now I can require all of my custom dependencies relative to the root folder of my project no matter what directory I'm in. If I move a file using the dependency, the path to my dependency will always resolve correctly since NodeJS looks in the node_modules folder at the root of your project first.

var my_module = require('lib/my_module.js');