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.

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.

Was getting this when I was trying to run cordova commands. Steps to resolve:

Windows

  1. 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.
  2. Navigate to Start > Computer > Right-click Properties > Advanced system settings
  3. Under the Advanced tab, select Environment Variables
  4. Under System variables, select "Path" variable
  5. Find nodejs EXE, usually "C:\Program Files (x86)\nodejs\"
  6. Cut and paste this to the beginning of the "Path" variable. Ensure the paths are separated by a ";"
  7. 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.

You can do either of following two things you can do to overcome this problem:

  1. Remove <Program Files (x86)>\CA\SharedComponents\PEC\bin from PATH environment variable.
  2. 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!

But the problem with above approaches is, you then break Harvest SCM's functionality. 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%

Explanation: Second line of the script (temporarily) deletes the harvest executable's path from PATH variable and adds the Node.js's path (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 with modified environment variables, enabling you to 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.

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.

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”)