0

I have downloaded the node.js zip and extracted it in a folder in my Windows PC. I have set the Path to the extracted folder and can execute the node and npm command from command line. I installed external modules using npm command and a folder node_modules got created inside my extracted folder containing all my external modules. Now I created a nodejs file Test.js which loads these external modules. The Test.js can only be executed successfully if it is executed from the extracted folder. Otherwise external modules are not getting loaded. Can you suggest how I can execute the Test.js from any location on my PC?

regards Souvik Saha Bhowmik

1 Answers1

0
npm install -g <package>

You can install the npm packages globally so that your Test.js can access the npm packages from anywhere on your pc.

  • Thanks Chetan. Tried that by using the below command npm install -g watson-developer-cloud --save watson-developer-cloud is my package. But still its giving "Cannot find module" – Souvik Saha Bhowmik May 30 '17 at 09:45
  • Most probably you NODE_PATH is not pointed to the location where the npm packages are getting installed. You should check the NODE_PATH and where the npm packages are getting installed. For setting up path in various windows platform you can look at : https://stackoverflow.com/questions/9587665/nodejs-cannot-find-installed-module-on-windows – Chetan Kanjani May 30 '17 at 10:33
  • just require the module by passing path of the module in your app, it's simpler – Mukul Jain May 30 '17 at 10:47