Reputation: 9579
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.
Upvotes: 13
Views: 17789
Reputation: 22270
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:
<Program Files (x86)>\CA\SharedComponents\PEC\bin
from PATH
environment variable.<Program Files (x86)>\nodejs
to the beginning of the PATH
environment variable (This is the currently accepted answer from djrpascu).There are two problems with the above approaches:
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.
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.
Upvotes: 18
Reputation: 81
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
Upvotes: 3
Reputation: 1311
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"
Upvotes: 1
Reputation: 179
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"
Upvotes: 5
Reputation: 19
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”)
Upvotes: -1
Reputation: 1813
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.
Upvotes: 2
Reputation: 410
Was getting this when I was trying to run cordova commands. Steps to resolve:
Windows
Upvotes: 19
Reputation: 9579
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.
Upvotes: 0
Reputation: 677
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
Upvotes: 0