Friday, December 19, 2014

Node.JS Error "Cannot find module '...'"

Setting up NodeJS is generally a smooth process. There is one thing need to be taken care of manually: set up environment variable NODE_PATH. This variable must point to the npm global installation location, otherwise you NodeJS application may have problem starting with error message like this:
Error: Cannot find module 'XXX'

In Windows, the easiest way is to go Computer > Properties > Advanced System Settings > Environment Variables > User Variables > New

After the configuration, need to exit the current command line and start a new one in order to see the environment variable in effect.