Q:

NPM require('tar') can not find module error

I installed tar and fstream using npm and after that i ran some commands. output is :
Your environment has been set up for using Node.js 0.10.18 (ia32) and npm.
C:\Users\abc>npm --version
1.3.8

C:\Users\abc>npm list
C:\Users\abc
├── chrome-rdebug@0.0.9
├─┬ fstream@0.1.24
│ ├── graceful-fs@2.0.1
│ ├── inherits@2.0.1
│ ├── mkdirp@0.3.5
│ └── rimraf@2.2.2
├── mime@1.2.11
├── q@0.9.7
├─┬ request@2.27.0
│ ├── aws-sign@0.3.0
│ ├── cookie-jar@0.3.0
│ ├── forever-agent@0.5.0
│ ├─┬ form-data@0.1.1
│ │ ├── async@0.2.9
│ │ └─┬ combined-stream@0.0.4
│ │   └── delayed-stream@0.0.5
│ ├─┬ hawk@1.0.0
│ │ ├── boom@0.4.2
│ │ ├── cryptiles@0.2.2
│ │ ├── hoek@0.9.1
│ │ └── sntp@0.2.4
│ ├─┬ http-signature@0.10.0
│ │ ├── asn1@0.1.11
│ │ ├── assert-plus@0.1.2
│ │ └── ctype@0.5.2
│ ├── json-stringify-safe@5.0.0
│ ├── node-uuid@1.4.1
│ ├── oauth-sign@0.3.0
│ ├── qs@0.6.5
│ └── tunnel-agent@0.3.0
├─┬ tar@0.1.18
│ ├── block-stream@0.0.7
│ └── inherits@2.0.1
└─┬ ws@0.4.30
  ├── commander@0.6.1
  ├── nan@0.3.2
  ├── options@0.0.5
  └── tinycolor@0.0.1

C:\Users\abc>node --version
v0.10.18

Now in running node.js when i do require('tar') i get
> require('fstream')
Error: Cannot find module 'fstream'
    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 repl:1:2
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
> require('tar')
Error: Cannot find module 'tar'
    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 repl:1:2
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)

What should i do ?

A:

The error means you're trying to require() those modules in a directory that never resolves to the one you've shown, which is C:\Users\abc\node_modules.
If you were in a directory such as C:\Users\user2, the modules would never resolve, because modules would be checked for in this manner:
C:\Users\user2\node_modules
C:\Users\node_modules
C:\node_modules

To fix this problem, move to a directory which is a child of a directory which shares a parent directory with the node_modules folder, or install the modules globally with the -g flag.

