Why doesn't node.js load the module I require?

I have node.js install on linux, and file.js. In the same directory I have node_modules directory with lru-cache module.

file.js does the following:

var lrucache = require('lru-cache')

But when I run it, it raises the following error:

Error: Cannot find module 'lru-cache'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/opt/file.js:58:12)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

What is the problem? the same is working in other linux system.

Most node modules will have their own set of package dependencies so you cannot just copy the folder or clone the repository without making sure you are satisfying the module's dependencies.

The easiest way would be using npm for ALL package installations.

After you have run npm init in your project's root directory to set up your package.json use

$ npm install modulename --save

to install a package AND its dependencies. You can now safely use

var module = require('modulename');

throughout your whole project.

In case you cannot install your package via npm make sure all of its dependencies are installed as well by navigating to node_modules/modulename and running npm install (no arguments) here. This will install all dependencies that are listed in the modules own package.json file.