"npm" is not recognized - node.js

So, I am trying to use command prompt for something. But it isn't working.
The steps were, get Node.js. Download a dropbox file of what I need. Copy the path thing that I use to get to the file in File Explorer.
Turn on Command Prompt type in "cd C:\Users\Evan\Desktop\GoAniFire-master_10.zip" and it worked.
I have Node installed, but then when i type in "npm install" after i hit enter on the last step. Nothing besides a error saying "npm isn't recognized" pops up, I have no idea what to do as I am new to Node.js and only recently started using command prompt. ;-;'
-Nate

If you installed Node from the official site, you should already have the Node Package Manager. You're likely receiving this error because Node isn't in your Path, so your command prompt doesn't know what it's looking for.
Open Control Panel -> System and Security -> System -> Advanced System Settings -> Environment Variables
In "User variables" or "System variables" find the variable Path. (If it doesn't exist, create it.)
Add your node.js folder path at the end of the variable value, beginning with a semicolon separating it from previous values. e.g. ;C:\Program Files\nodejs
Restart your command prompt.
This should work.

Make sure you installed node. Try restarting your computer first. If that doesn't work follow what user Elo wrote.

Open Control Panel -> System and Security -> System -> Advanced
System Settings -> Environment Variables
In User variables find variable PATH and add path to nodejs. Usually
-> C:\Program Files\nodejs;. If variable doesn't exists, create it.
Restart PC and IDE.
If you're using VSCode, close old terminal and open a new one. Even
when I did everything VSCode could not see node + npm, because old
terminal was broken.

Related

How to run node commands from vscode

I've installed node and npm. I'm able to run node apps from Windows cmd but when I try using the vscode terminal, it says node is not recognized as an internal or external command. Please help me fix this
In Windows, you need to set the node.js folder path into system variables or user variables.
open Control Panel -> System and Security -> System -> Advanced System Settings -> Environment Variables
in "User variables" or "System variables" find variable PATH and add node.js folder path as value. Usually it is C:\Program Files\nodejs;. If a variable doesn't exist, create it.
Restart your IDE or computer.
It is useful to add also "npm" and "Git" paths as variable, separated by a semicolon.

Node & Npm not recognized by WebStorm's terminal

I have paths to Node and NPM in both my user defined environment variable PATH and in system variable Path.
For node: C:\Program Files\nodejs
For npm: C:\Users\Username\AppData\Roaming\npm
Now node and npm are recognized by Windows Command Prompt but not by WebStorm's terminal. I get error:
'node' is not recognized as an internal or external command
Does anyone know what is problem? I could use WebStorm's terminal normally till today, but something went wrong and now I'm stuck.
EDIT:
echo %PATH% screenshot:
Settings/Tools/Terminal
screenshot:
I had similar issue. I had to select File -> Exit from the IntelliJ application as opposed to using IntelliJ's internal restart option: File -> Invalidate Caches / Restart -> Just Restart.
I had the similar problem like this.I was working with my project with another computer. and after that i decide to work with this project with my computer.so after moving the Files of project. i installed the Node.js and i had all of the paths about Node but when i was want to Run the project. i had this problem. i search a lot but nothing works. so i guess maybe when i restart my computer the new paths of variable system will work well. i restarted and my problem solved!
For those who are encountering this problem when you try to edit the run configuration, you have to put "start" as the command instead of "npm". By default Webstorm knows it's a npm project so it already starts with npm, you simply have to put the start command after that.

Command prompt not recognizing MongoDB even when added to environment PATH

I am new to the MEAN stack and am trying to implement a tutorial here:https://scotch.io/tutorials/build-a-restful-api-using-node-and-express-4
I am simply trying to install packages I need which are both node.js, express,js, and MongoDB.
My steps after trying to troubleshoot:
I have installed MongoDB 3.2.1 from their site onto my local machine and it is stored at path C:\Program
Files\MongoDB\Server\3.2\bin\
(I can navigate to C:\Program Files\MongoDB\Server\3.2\bin in my
command prompt window and type mongo and have it run)
I went to Control Panel -> System Settings -> Security -> Advanced -> Environment Varaibles -> and under system varialbles:
Earlier I had to add a path for node.js (C:\Program Files\nodejs works
fine for running node at any directory level)
So I tried adding a system variable: MongoDB at "C:\Program
Files\MongoDB\Server\3.2\bin\mongo"
So the ultimate goal is for me to be able to navigate to a folder strucutre on my desktop and run:
"node --version"
"express --version"
"mongo --version"
and have them all be properly installed and available so that I can move on to my application creation.
Any help would be appreciated, thanks.
The command line works by looking in all of the directories specified by the PATH environment variable.
From what I can see, you've included the name of the executable (mongo) in the PATH, when you just need to include the directory.
Just for completeness, on my PC, the PATH variable looks something like this:
C:\Program Files (x86)\Python35-32\Scripts\;C:\Program Files\apache-maven-3.3.9\bin;C:\Program Files\MongoDB\Server\3.2\bin
Basically path variable in a system stores the paths to executable files and programs.
1 System.
2 Advanced system settings.
3 Environment Variables.
4 Double click on 'path' in your User tab.
5 click 'New'.
6 Then add your mongo bin location.
ex:- my one --> C:\Program Files\MongoDB\Server\3.6\bin.
7 Click OK.
Then try in cmd again for the result
I had the same problem when I did the installation on ParrotOS, when I wanted to run the Mongo shell on the terminal with the command mongo it prompted me that the the command wasn't recognize. Same problem with Windows after I edited the variable path.
The command mongod ran for me the shell in both OS without problems. It could be something that was added with new versions of MongoDB.
If someone else knows more about what this happens, ill be more than happy to know.

Installing Node.js (and npm) on Windows 10

I had some issues trying to install Node on Windows 10 and found the solution.
The error was as follows:
C:\Users\Stephan>npm
Error: ENOENT, stat 'C:\Users\Stephan\AppData\Roaming\npm'
The solution is below.
Edit:
It seems like new installers do not have this problem anymore, see this answer by Parag Meshram as my answer is likely obsolete now.
Original answer:
Follow these steps, closely:
http://nodejs.org/download/ download the 64 bits version, 32 is for hipsters
Install it anywhere you want, by default: C:\Program Files\nodejs
Control Panel -> System -> Advanced system settings -> Environment Variables
Select PATH and choose to edit it.
If the PATH variable is empty, change it to this: C:\Users\{YOUR USERNAME HERE}\AppData\Roaming\npm;C:\Program Files\nodejs
If the PATH variable already contains C:\Users\{YOUR USERNAME HERE}\AppData\Roaming\npm, append the following right after: ;C:\Program Files\nodejs
If the PATH variable contains information, but nothing regarding npm, append this to the end of the PATH: ;C:\Users\{YOUR USERNAME HERE}\AppData\Roaming\npm;C:\Program Files\nodejs
Now that the PATH variable is set correctly, you will still encounter errors. Manually go into the AppData directory and you will find that there is no npm directory inside Roaming. Manually create this directory.
Re-start the command prompt and npm will now work.
go to http://nodejs.org/
and hit the button that says "Download For ..."
This'll download the .msi (or .pkg for mac) which will do all the installation and paths for you, unlike the selected answer.
In addition to the answer from #StephanBijzitter I would use the following PATH variables instead:
%appdata%\npm
%ProgramFiles%\nodejs
So your new PATH would look like:
[existing stuff];%appdata%\npm;%ProgramFiles%\nodejs
This has the advantage of neiter being user dependent nor 32/64bit dependent.
New installers (.msi downloaded from https://nodejs.org) have "Add to PATH" option. By default it is selected. Make sure that you leave it checked.
Everything should be installed in %appdata% (C:\Users\\AppData\Roaming), not 'program files'.
Here's why...
The default MSI installer puts Node and the NPM that comes with it in 'program files' and adds this to the system path, but it sets the user path for NPM to %appdata% (c:\users[username]\appdata\roaming) since the user doesn't have sufficient priveleges to write to 'program files'.
This creates a mess as all modules go into %appdata%, and when you upgrade NPM itself - which NPM themselves recommend you do right away - you end up with two copies: the original still in 'program files' since NPM can't erase that, and the new one inn %appdata%.
Even worse, if you mistakenly perform NPM operations as admin (much easier on Windows then on *nix) then it will operate on the 'program files' copy of NPM node_modules. Potentially a real mess.
So, when you run the installer simply point it to %appdata% and avoid all this.
And note that this isn't anything wierd - it’s what would happen if you ran the installer with just user priveleges.
You should run the installer as administrator.
Run the command prompt as administrator
cd directory where msi file is present
launch msi file by typing the name in the command prompt
You should be happy to see all node commands work from new command prompt shell
I had the same problem, what helped we was turning of my anti virus protection for like 10 minutes while node installed and it worked like a charm.
The reason why you have to modify the AppData could be:
Node.js couldn't handle path longer then 256 characters, windows tend to have very long PATH.
If you are login from a corporate environment, your AppData might be on the server - that won't work. The npm directory must be in your local drive.
Even after doing that, the latest LTE (4.4.4) still have problem with Windows 10, it worked for a little while then whenever I try to:
$ npm install _some_package_ --global
Node throw the "FATAL ERROR CALL_AND_RETRY_LAST Allocation failed - process out of memory" error. Still try to find a solution to that problem.
The only thing I find works is to run Vagrant or Virtual box, then run the Linux command line (must matching the path) which is quite a messy solution.
For me I had to delete the nodejs folder in \program files and then when I went to install through the msi it worked. Seemed like when I uninstalled Node it didnt actually delete this file
I had the same problem, but after trying everything on this post unsuccessfully, I just had to restart.
So if you haven't tried restarting the computer after the installation, try it.
Restart your computer after installation

Running node.js code just displays a node identifier

I have the following code in a file called server.js.
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8124);
console.log('Server running at http://127.0.0.1:8124/');
I use the command prompt and naviage to the folder where the file recides and then the run the command
node server.js
But I don't get the expected output. Instead I get
The node identifier for {My Machine Name} is v2hrfnqaj.
Note: I already have node installed in my machine and it was working fine.
Was getting this when I was trying to run cordova commands. Steps to resolve:
Windows
In CMD prompt, type "where node". As Michael mentioned, this shows
you the likely culprit, that you have 2 nodejs EXEs installed on
your machine.
Navigate to Start > Computer > Right-click Properties > Advanced system settings
Under the Advanced tab, select Environment Variables
Under System variables, select "Path" variable
Find nodejs EXE, usually "C:\Program Files (x86)\nodejs\"
Cut and paste this to the beginning of the "Path" variable. Ensure
the paths are separated by a ";"
Open a new CMD prompt and try cordova again
This happens when Harvest SCM is installed on your system. It has an executable with the name node.exe at <Program Files (x86)>\CA\SharedComponents\PEC\bin (where <Program Files (x86)> is your x86 program files folder). This path is present in your PATH variable before the path to Node.js's node.exe.
Update: You don't need the elaborate scheme listed in the old answer. You just have to open the Command Prompt and run:
C:\> nodevars
nodevars.bat is a small script that does essentially the same thing described below (but in a safer way). If you have node installed, this script should be in path. (If not make sure to add C:\Program Files\nodejs to your path. But make sure to append it in the end so Harvest SCM does not break).
Everything below is outdated, but I will leave it for the curious reader.
You can do either of following two things you can do to overcome this problem:
Remove <Program Files (x86)>\CA\SharedComponents\PEC\bin from PATH environment variable.
Add/move <Program Files (x86)>\nodejs to the beginning of the PATH environment variable (This is the currently accepted answer from djrpascu).
You can do better!
There are two problems with the above approaches:
You break Harvest SCM's functionality.
If you do not have elevated privileges to change PATH, you are out of options. (Thanks #Glats)
So I created this little batch file, and put it in a directory where I have several other personal scripts (this directory is in my PATH). Here's the gist for the script.
nodecmd.bat
#echo off
set path=%path:C:\Program Files (x86)\CA\SharedComponents\PEC\bin;=%;C:\Program Files (x86)\nodejs;
start %ComSpec%
Then the next time you want to run Node.js, instead of Command Prompt, you open the new script with "Run..." command.
Windows+R
nodecmd
A command prompt will appear. You can use this command prompt to run node without a hassle.
Explanation
This bit deletes the Harvest's executable's path from PATH variable:
%path:C:\Program Files (x86)\CA\SharedComponents\PEC\bin;=%;
And this adds the Node.js's path:
set path=...;C:\Program Files (x86)\nodejs;
The result is a string that contains the original PATH variable minus Harvest's path, plus Node's path. And it is set as PATH variable in the scope of current batch file.
Note: You might have to change the path's in the script to suit software installation folders in your system).
Next line, start %ComSpec% starts a Command Prompt. By this time, the PATH variabe is modified. With modified environment variables, you can run node within this new Command Prompt. The environment variable modification does not affect the rest of the system, making sure that Harvest SCM software runs without breaking.
Don't break your Harvest SCM by removing it from path. Try this one, open your windows command line (cmd) and then pass the following nodejs batch file so that it will set your command line to nodejs environment. Enjoy the node commands there.
C:> "C:\Program Files\nodejs\nodevars.bat"
You can also prioritize in the environments.
Steps:
Computer -> Right click -> Properties -> Advanced system settings -> Environment variables -> PATH(in system variables list) -> Edit -> Prioritize by moving up
This is old, but I ran into this same problem. Exact same message (with my machine name of course). The issue was that there was another node executable on the path, in C:\Program Files (x86)\CA\SharedComponents\PEC\bin. I'm on a windows machine, so running where node showed the two conflicting "node" executables in the path.
To fix the problem, I just removed the CA directory from the PATH environment variable.
I faced the same problem and simply changed the the name of node.exe file from Harvest. This hasn't broken anything from Harvest and I can keep working with it.
Change the Harvest's command name to node_.exe:
ren "C:\Program Files (x86)\CA\SharedComponents\PEC\bin\node.exe" "C:\Program Files (x86)\CA\SharedComponents\PEC\bin\node_.exe"
I think you're running the wrong node command.
Try locating or re-downloading your nodejs installation and add it to your path as the first directory. If you're running linux or unix you can try 'which node' to see what is being run.
Note that in some cases, the node.js executable is called nodejs so you may want to try
nodejs server.js as well
I used the node.js command prompt, instead of the windows default command prompt and it worked for me. Did not know why it did't work in the windows default command prompt.
I was also running with same issue - while defining the path for windows use below parameter
Windows:
set NODE_PATH=C:\nodejs
OR
Set the environment variable for nodejs
NODE_PATH=C:\nodejs
Path= C:\nodejs
(append the path contain this string “c:\nodejs”)

Resources