NodeJS + NPM “Cannot find module”

TL;DR: install your NPM packages globally. Like this (where “homebridge” is whatever package you are installing):

sudo npm install homebridge -g

This was driving me crazy. I have been trying to install a couple of NPM packages with dependencies, and run them at startup as a service on an Ubuntu server. I knew the packages weren’t ending up in the right place (even when run as sudo), but I couldn’t figure out why.

Using the -g (global) option cleared everything back up. Now all the dependencies are installed for all users, and my service starts without errors.

The errors were like these:

Error: Cannot find module 'request'

Continue reading