Scope after npm installs node coap

  node.js, question

The problem has been found, but the global variable NODE_PATH is not defined.


I downloaded the source code 0.12.7 from nodejs website, compiled and installed, and the version after installation is as follows:
node–v0.12.7
npm –v2.11.3
Then i installed node coap with the following command:
sudo npm install coap -g
Then I saw the coap folder under /usr/local/lib/node_modules/,
Enter examples to run.node server.js, can run normally.

Then I switch to /home, create a demo folder, copy server.js here, and run a prompt error.

module.js:338
 throw err;
 ^
 Error: Cannot find module 'coap'
 at Function.Module._resolveFilename (module.js:336:15)
 at Function.Module._load (module.js:278:25)
 at Module.require (module.js:365:17)
 at require (module.js:384:17)
 at Object.<anonymous> (/home/uto/works/app-demo/app.js:1:83)
 at Module._compile (module.js:460:26)
 at Object.Module._extensions..js (module.js:478:10)
 at Module.load (module.js:355:32)
 at Function.Module._load (module.js:310:12)
 at Function.Module.runMain (module.js:501:10)

This should be a reminder that coap is not installed.
So my question is, is npm -g not globally effective after installation? Why can’t it be executed in the home directory

The problem has been found, but the global variable NODE_PATH is not defined. Modify /etc/profile and add node _ path =/usr/local/lib/node _ modules.