2

I am new to NodeJS. I am trying to use npm on Windows 8.

I have installed using chocolatey, cinst nodejs.install (version 0.10.17). I installed as administrator (and would prefer to run npm as a normal user).

Node itself seems to be working, I can use the REPL to run simple programs.

If I try to install something using npm, I get cannot find module:

> node npm install express

module.js:340
    throw err;
          ^
Error: Cannot find module 'C:\Users\Klas\Documents\My Dropbox\mina egna\tech\node\webserver\npm'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

I have read the answers on Nodejs cannot find installed module on Windows? but unfortunately it is still unclear to me what I have to do.

I have tried setting NODE_PATH:

  1. In trying to follow this answer, I have tried setting it to C:\Users\Klas\AppData\Roaming\npm\node_modules (but I had to create both the npm and the subfolder node_modules myself)
  2. I have tried creating a folder c:\node\node_module (according to this advice, even though the installation did not even create a c:\node folder) and setting it to that.
  3. I have tried setting it to C:\Program Files\nodejs\node_modules\npm\node_modules (which did exist after installation)
  4. I have also tried to create a node_modules folder below the current working directory. As I understand it that is where local npm will be installed?

None of these helped. So it seems to me that setting NODE_PATH is not the solution?

Using the -g flag makes no difference (I would prefer not to use it).

I get the same error both as normal user and as administrator (I would prefer to be a normal user).

I get the same error no matter where I execute the command, except when I do it in C:\Program Files\nodejs, where I get

basedir=`dirname "$0"`
       ^
SyntaxError: Unexpected token ILLEGAL
   at Module._compile (module.js:439:25)
Community
  • 1
  • 1
Klas Mellbourn
  • 42,571
  • 24
  • 140
  • 158

1 Answers1

3

Not using windows, but I'm pretty sure it's just npm install express on windows too.

Andreas Hultgren
  • 14,763
  • 4
  • 44
  • 48
  • 1
    Doh! If I do `npm install express` inside the REPL I get the message `npm should be run outside of the node repl, in your normal shell`, which I interpreted as `npm` being a subcommand to `node`, that is why I ran `node npm install express` in `cmd.exe`. Embarrassing newbie mistake. – Klas Mellbourn Sep 01 '13 at 09:51
  • Those other articles threw me for a loop, as they talked so much about `NODE_PATH`. As far as I can see, you don't have to set `NODE_PATH` at all, if you are content with local installs (which is recommended) – Klas Mellbourn Sep 01 '13 at 18:27
  • Well there are also npm modules that are just command line tools for daily usage (e.g. simple-HTTPServer). For those to be available via command line you need them in your NODE_PATH. – Andi-lo Dec 02 '16 at 10:23