‘npm’ is not recognized..” vs code error [ Fixed ]

If you are seeing this “npm is not recognized vs code” error, you’re not alone:

npm : The term ‘npm’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

We need to add Node js to environment variables in your Windows machine to fix this error.

Sometimes we can fix it easily by this simple one line code in your Terminal within VS Code:

SET PATH=C:\Program Files\Nodejs;%PATH%

…but it may not work always!

If the above line of code didn’t work, here’s how to add the environment variable so you can use the npm command within your VS Code terminal: (all the respective screenshots are also provided below the steps)

How to set Node JS Environment Variables in Windows 11:

Step 1: Right click on Start menu (Windows icon – bottom left). Click to open System.

Step 2: Click on ‘Advanced system settings

Step 3: Click on Advanced tab; then on Environment Variables.

Step 4: In the ‘Environment Variables‘ window, under ‘User Variables‘, click on ‘New…‘ button.

Step 5: Within the ‘Variable name‘ filed, type “NODE_ENV” without the double quotes. Next, in the ‘Variable value‘ field, type ‘production‘ without the single quotes.

Press OK.

Here are the screenshots

image 2
image 1
image 4
image 6
image 7

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

seventeen − 14 =