I tried to install some node libraries globally (in my case I was installing nestjs CLI).
npm install -g @nestjs/cli
Npm installed that package properly. After that when I tried to use the nest command then it was not working.
It was showing the following message:
‘nest‘ is not recognized as an internal or external command, operable program, or batch file
You can face this issue with some other package, but the solution will be the same for all.
What caused the issue?
The reason was the path of the node packages global installation was not present in the windows environment path.
So the packages were installed properly and all necessary files were created for executing that command. But as that path was not recognized by windows, so it was throwing an error.
Solution
Check your path for global packages for node. Use the following command for that:
npm root -g
You will get some responses like the below:
C:Usersyour_user_nameAppDataRoamingnpmnode_modules
Whatever the path is copy that, except the node_modules part (ignore that node_modulespart).
So you will copy something like this.
C:Usersyour_user_nameAppDataRoamingnpm
Add the path to your environment variable path
- Press the Windows key and in Search, search for and then select: Environment Variables.
- Click the edit the system environment variables link.
- When the program opens, you should see a button named ‘Environment Variables’, click on that.
- Under the system variables, the section finds the entry which has a variable name as ‘Path’.
- Select that and client on edit. on the new screen click on the new button and add the path that you copied here.
- Save and close the setting application.
You are good to go. The command that you wanted to execute should work now.
You may need to close the command prompt and open it again, for that new environment variable to be available, and the command to work.
This solved my problem.
Thanks !
Happy to help, Shubam.