Node.JS cannot find module 'xml2js' (Windows)

OS: Windows 7 64-bit

Need to do parsing xml-file using Node.js.

Using a library for parsing xml2js.

Xml2js installed using the command "npm install xml2js".


However, if you run the code:

var fs = require ('fs'), xml2js = require ('xml2js'); 

var parser = new xml2js.Parser (); 
fs.readFile ('<path to the xml-file>', function (err, data) {
     parser.parseString (data, function (err, result) {
         console.dir (result); 
         console.log ('Done'); 
     }); 
});

an error:

module.js:340
    throw err;
          ^
Error: Cannot find module 'xml2js'
    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> (<путь до js-файла>:3:14)
    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)

Tell me, please, how to solve the problem?

make sure the directory ./node_modules/xml2js is exist.

when you run npm install somemodule at D:/test, it will be stored to D:/test/node_modules/somemodule, then you can require this module in D:/test/*.js, and you can not require it at D:/other/place/*.js. If you hope the module can be required anywhere you should run :

npm install somemodule -g