followed steps in the node.js server on how to install node.js, when giving the following command; node -v or nvm -v I get the following error message : The term 'node' 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. At line:1 char:1
+ CategoryInfo : Ob
jectNotFound: (node:String)
[], CommandNotFoundException
+ FullyQualifiedErrorId : Co
mmandNotFoundException
to get the version of node.js installed
I'm going to assume a few things here:
I had a similar issue to this (using Windows 11).
The main issue lies in that PowerShell profiles are not created automatically upon installation (for some reason). The profile path needs to exist for the fnm script (containing fnm environment variables) to run--as mentioned in the fnm GitHub page
Steps:
Here is how to set up the PowerShell profile:
First, check that your profile does not exist. in PowerShell, run: notepad $profile.
If Notepad cannot find the path, continue below, otherwise, jump to step 3.
Open PowerShell using admin access and paste the code:
ps:> if (!(Test-Path -Path $PROFILE)) {
New-Item -ItemType File -Path $PROFILE -Force
}
This basically create the profile path. (script from Microsoft).
Restart PowerShell.
Now we're going to make sure PowerShell is able to run scripts. Open it and run:
ps:> Get-ExecutionPolicy
# If it says Restricted, then it won't run node, or it's associated env variables.
To change it, open PowerShell in admin access, and use this code to change the restriction for PowerShell execution policies:
ps:> Set-ExecutionPolicy -ExecutionPolicy Unrestricted
# Accept the change and restart PowerShell again.
This is my preferred option, since I have not experimented with the other options--found in the link in this bullet point.
ps:> notepad $PROFILE
# append the script from the `fnm` documentation into the file
ps:> fnm env --use-on-cd | Out-String | Invoke-Expression
node --version and it should work with no issue.Copy the command:
fnm env --use-on-cd | Out-String | Invoke-Expression
Into $profile to save the settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With