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?
I was also facing the same issue. Here's what I did:
Install the module using following:
$ npm install -g *module_name*
Then go to any parent dir of your project dir (it can be project dir itself) and run the following command:
$ npm link *module_name*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With