Nodejs NPM does not work

Asked

Viewed 2,215 times

2

Guys, I installed Node normally and added it to the environment variable; I did some math operations to test and it worked. When I tried to install modules (socket.io and express) it did not work, even running as administrator. I tried to check the command to test if npm is installed, but I get an error back. The command was to check the npm version: npm -v and it also didn’t work with Node even though it was up and running: node -v.

inserir a descrição da imagem aqui

  • You are doing the commands wrong. Do not enter Node mode... do "Node -v" and not "Node [enter] -v".

  • Perform the functions npm outside the Node command. Just open your cmd and enter the command npm .... If I haven’t made myself clear, feel free to question.

  • I understand perfectly. It worked. I was actually running the commands wrong, but now the problem is different: when I tried to install the socket.io several errors occurred.

  • I believe this question has been solved so :) If you need help with the other mistakes, you can post new questions and see what to do when having a question answered

  • 2

    @Ivan, ideally you would open another question to talk about these errors you are having when installing the package. Just to keep the organization of the site, and when you open the next question about the error try to copy the entire installation log, only that image there does not help much, you would need to know what was written above.

3 answers

2

You’re running in mode node and it shouldn’t be like this.

When you write only node you enter a Javascript mode, that is, you are in a Javascript console. That’s when you write npm it will interpret as a Javascript variable and says it is not closed...

Use directly on console:

$ npm -v
$ # ou
$ node -v
  • I get it. You really were doing it wrong. Thank you!

1


You are just executing in the wrong place your command. The npm is the Node Package Manager, you do not need to "start" the node (Node + enter on your console) to use it. Open the command and type npm -v directly on the command line.

C:\Users\pfortesc>npm -v
2.14.4

As explained by @Sergio, the way you were doing the node was trying to find the variable npm, as it does not exist, the exception was fired.

  • Really. I was doing it wrong.

1

node and npm are two separate programs and you were trying to run the npm from within the node, which clearly would not work. That is, you just run the npm as a normal command in Windows Command Prompt.

Instead of doing this:

C:\Users\zignd>node
> npm -v
ReferenceError: npm is not defined
    at repl:1:1
    at REPLServer.defaultEval (repl.js:132:27)
    at bound (domain.js:254:14)
    at REPLServer.runBound [as eval] (domain.js:267:12)
    at REPLServer.<anonymous> (repl.js:279:12)
    at REPLServer.emit (events.js:107:17)
    at REPLServer.Interface._onLine (readline.js:214:10)
    at REPLServer.Interface._line (readline.js:553:8)
    at REPLServer.Interface._ttyWrite (readline.js:830:14)
    at ReadStream.onkeypress (readline.js:109:10)

Do it:

C:\Users\zignd>npm -v
2.10.1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.