Skip to content
Advertisement

Running npm globally installed packages

Can someone please explain how do node’s globally installed behave. It is really confusing me. If I install a package (with executables) such as http-serverglobally I can run it with:

http-server

But if I do

node http-server

I get

module.js:339
    throw err;
    ^

Error: Cannot find module '/path/to/current/dir/http-server'
    at Function.Module._resolveFilename (module.js:337:15)
    at Function.Module._load (module.js:287:25)
    at Function.Module.runMain (module.js:457:10)
    at startup (node.js:136:18)
    at node.js:972:3

I suspect my ternpackage in emacs is trying to run it with node hence breaking. Why is this happening? Why can’t node find the path to it’s own modules?

Advertisement

Answer

rahul@Rahul-Machine:~$ node blalal 
module.js:338
throw err;
^

Error: Cannot find module '/home/rahul/blalal'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:286:25)
at Function.Module.runMain (module.js:475:10)
at startup (node.js:117:18)
at node.js:951:3

ooh same error

this is because i first command you are actually trying to access a global variable but in second you are some where in your file hierarchy and from there you are saying that you want to access that package so you are wrong if you want to execute that global package try

whereis http-server

then go to that directory and find the file package.json and then open it and find the “main” property and there you get a file name then type

  node index.js

your file will be executed

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement