Override System Environment variable path in windows (not admin access) - node.js

Issue is very peculiar, I have a version of NodeJS installed in Windows (in program files x86) and a newer version of software downloaded and exe is extracted.
The installed NodeJS (node.exe) 's path is included in system path variable. I added the extracted path to user environment path variable.
After doing my bit of RTFM I came to know that in case path variable both system and user environment variables are combined and the system gets the precedence.
Is there any way I can override (or nullify) the system variable's PATH with user variable's path ? or can the precedence of reading variables be changed ?

In cmd, type
set PATH=D:\Path_To_Local_Folder;%PATH%
node
It will start node from your local folder.

Using Powershell you can set the folder Node runs from so that it picks up the new version of Node for that instance of Powershell.
Open Powershell
Set the path variable to be your node folder
$env:Path = "C:\yournodefolder";
Running node --version should now display the version of node from your new folder.

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.

Running npm in cmd giving me errors, I just installed nodejs msi on windows

I installed nodejs in Windows system from official website and npm giving errors:
CALL "C:\Program Files\node js\\node.exe" "C:\Program Files\nodejs\\node_modules\npm\bin\npm-cli.js" prefix -g' is not
recognized as an internal or external command, operable program or batch file.
I have given all sorts of paths. Please help me.
http://prntscr.com/gso39z
Add the following paths to your PATH environment variable
%USERPROFILE%\AppData\Roaming\npm
C:\Program Files\nodejs\
(note that i have windows 10, where your programs are installed can differ as per your windows version)
To permanently set PATH environment variable, follow these steps:
This PC/ My Computer Properties
Advanced System Settings, (right side)
from popup, click environment variable
select PATH environment variable under system variable, (not user variable) then click edit
Click new, and copy and paste one of the path (given) there.
new again and paste second path
to check if its set or not, goto terminal, and type PATH
note: if you type PATH, its value will be displayed, but if you type %PATH% , each of its value will act as a command input to terminal (windows terminal -_-).
Start the process by being an administrator.
Open up your command prompt as an administrator.
And if you are using older version of node say 6.9, please upgrade to 6.10, it may solve your problem.

nvm: reference "default" node version path in Shell script

I'm writing a daemon script for Linux Debian, and I'd need to be able to access the $NVM_BIN shell environment variable, or somehow reference the path to the current "default" Node version as set in nvm.
Several of these daemon scripts will be running on the system.
Since all these scripts can share the same Node version, I'd like to reference some variable that gets automatically updated when I install a new version of Node and define it as "default", without having to manually change the Node JS reference in each script.
Is this possible?
Thanks!
I've finally found a way to do it.
The first line of the shell script must be:
#!/bin/bash
(part of the problems I had was related to the fact that my first line was #!/bin/sh instead)
Then, to access nvm variables or commands you must first source them with:
source <your_path>/nvm/nvm.sh
(where <your_path> needs to be replaced with the path to your nvm folder).
Now you can get the path to the node folder in two ways.
1. Through a standard nvm variable
$NVM_BIN
2. Directly "asking" to nvm
NVM_BIN=<your_path>/`nvm version`/bin/
Nice.

node is not recognized as an internal or external command but is in PATH

Although I've follow suggestions from:
'node' is not recognized as an internal or an external command, operable program or batch file while using phonegap/cordova
Node.js doesn't recognize system path?
‘ant’ is not recognized as an internal or external command...
I'm having an strange issue: Resume, although node path is list in Path, it doesn't find node.
Workflow:
Microsoft Windows [Version 6.3.9600] //Running CMD on windows 8.1
(c) 2013 Microsoft Corporation. All rights reserved.
I followed suggestions in SO, adding variable to Environment Variables, and it's display Ok in Path:
C:\Users\myUser>path
PATH=c:\Program Files (x86)\nodejs ; (...omitted...) //So folder is there
Next line will fail
C:\Users\myUser>call jasmine-node spec
'node' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\myUser>cd "c:\Program Files (x86)\nodejs" //So I move to the folder list before...
But if I move to folder list in Path, then it works OK.
c:\Program Files (x86)\nodejs>call jasmine-node spec
> (...omitted...) //Exec OK.
c:\Program Files (x86)\nodejs>node
> //Exec OK. Waiting...
It seems contradictory.
The nodejs directory in your PATH isn't recognized because there's a space before the semicolon, so Windows is looking for a directory with a space at the end of the name, which doesn't exist.
Error: 'node' is not recognized as an internal or external command
The problem is may be the node is not installed on the machine in which the application is running.
Then install it and set the environment variable for nodejs.
Or
One more reason can be the nodejs path not set in the environment variable.
Check with the following -
open Control Panel -> System and Security -> System -> Advanced System Settings -> Environment Variables -> Path
the nodejs path should be available here.
If not available then add the following:
C:\Program Files (x86)\nodejs
OR
C:\Program Files\nodejs
Now Re-Run the application and the Error got resolved.
;C:\Program Files\nodejs\
Slash after \nodejs\ worked for me
Usually the environment variables are not effective till a system
Restart.
I suggest a System Restart for all those who face the same issue when doing a clean install.
This worked for me.
In Windows, you need to set node.js folder path into system variables or user variables.
1) open Control Panel -> System and Security -> System -> Advanced System Settings -> Environment Variables
2) 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 variable doesn't exists, create it.
3) Restart your IDE or computer.
It is useful add also "npm" and "Git" paths as variable, separated by semicolon.
If you did npm install jasmine-node -g you should just need to do jasmine-node spec (no call prefix).
If you've checked your PATH, and are sure that the path for node is added properly, then you're likely to face the problem while running node OR npm commands with CLI's other than the default command line interface of the operating system (e.g. Git bash in Windows).
The strange part is that you can check for node -v and npm -v in those CLIs, but for some reasons, they don't work well with those commands (especially when combined with install or update).
Possible Solution
Try running node with the default terminal for your OS.
I faced this issue even after adding node.exe to PATH. I wasn't able to run node command at random locations without running command prompt as administrator.
Solution to this issue is, you have to give full access permissions to this node.exe file for different user types. open the properties of node.exe, go to security tabs, check all the security options to the user on your local machine.
after doing this you should be able to access the node.exe file from any location.
things to check:
open CMD>Go to the directory where node.exe resides > type node -v > :
if it shows the version: Please add the same path (like>
PATH=C:\Programfiles\nodejs\;) in the OS path in environment variable (any of the
system or user variable, both work fine)
if it doesn't recognize, please add a variable PATHEXT=.exe; in the environment
variable (The PathExt is an Environment Variable that stores a list of the file
extensions for the operation system to execute) and save them.
Now open a new command prompt window and check.it must work.
After installing nodejs you have to restart your terminal or IDE .
C:\Program Files\nodejs
adding the path without the semi-colon did it for me...
For the issue which is coming "node' is not recognized as an internal or external command, operable program or batch file.", I have tried updating the path, but the issue didn't resolve. So I uninstalled and installed node.js and it worked for me.
The error:
node-is-not-recognized-as-an-internal-or-external-command
And the following solution:
Set Environment variable NODE_HOME as C:\Program Files\nodejs
Open cmd window and run:
cd "C:\Program Files\nodejs"
npm install connect
npm install -g appium
It's as simple as adding the location of nodejs (C:\Program Files (x86)\nodejs) to your PATH variable and restarting your application with "Run as administrator".

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