Cannot run node.js program in command prompt - node.js

Arch-noobie here. When I try to run a node.js program in windows command prompt by stating its location, it will invariably say "[stated location] is not recognized as an internal or external command, operable program or batch file."
In all answers to similar questions, in all node.js manuals, it is assumed you can just run a node.js file by calling it from its location. There will always be the suggestion of trying some "hello world" example BEFORE establishing a server and so on.
Even if I clean the command prompt with "prompt $ cmd", and then write the whole location manually, I get the same message.
Can anybody help me with this? Thanks in advance.

By default, your node.js should be installed in C:\Program Files\nodejs location. Check for it.
Next, look for environment variables to be set at C:\Program Files\nodejs\bin
You can follow this link to check for the PATH and environment variables.
Then, restart your system. It should start working.

make sure you are typing node NOT npm

Related

YEOMAN YO ERROR yo it is not recognized as an internal or external command, program or batch file executable.

When installing node.js for the first time and using the YEOMAN library, I found that it did not recognize the library despite installing it correctly.
When executing in console
yo swaggerize
Returns the error "yo it is not recognized as an internal or external command, program or batch file executable"
After several laps the problem is in node.js and in the PATH.
I post the solution in the next post.
The solutión for me, it's simple.
In windows-> go to pc properties->advanced configuration-> environment variables
Show Path variable and edit.
C:\Users\youruser\AppData\Roaming\npm;
C:\Program Files\nodejs;
Save restart your console and run the command again
Each and every thing was fine
only problem was path
so I set path in environment variable.
This path I set in environment variabel
C:\Users\user\.npm-packages
where 'user' is my user name, please use your user name.
Then my 'yo', 'bower' command start to executed
Thanks

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

Running Azure node.js Tools on Ubuntu

I have followed these instructions.
And as far as I can tell I have successfully installed node.js azure tools. No error - nothing to suggest it failed.
However, I cannot, and the documentation says, simple run "azure"...
Maybe there is something I am missing with node.js?
There are a few problems you may be experiencing.
First of all, I would ensure you are running Node.js v0.6.20. You can do this by opening the command prompt and running:
node -v
You should have v0.6.20 echoed back.
If this doesn't work, you may be missing a path variable to Node.js or the NPM cache. Verify the Environment variables exist by running [in the command prompt]:
path
you should see two paths:
%appdata%\npm
[x64 Machine]
%programfiles(x86)%\nodejs\
[x86 Machine]
%programfiles%\nodejs\
If this doesn't work, I would check to ensure that the azure module was loaded into the %appdata%\npm\node_modules directory.
It could be the PATH issue. In my case, the azure program is located at ~/.npm-global/bin.
run "export PATH=$PATH:~/.npm-global/bin". Or just add to bash source file

I can't run test with "vows test/*" command on windows. How to use it? node.js

I've installed vows as module of my project and I've added the path "node_modules\vows\bin" to my environment path variable of windows vista.
note: I've also renamed "node_modules\vows\bin\vows" to vows.exe, because without the extension I get this error: 'vows' is not recognized as an internal or external command,
operable program or batch file.
Now wherever I put "vows" in my cmd in windows nothing happens, I cd into my test folder and I run "vows myFirstTest.js" and nothing happens. (when I say nothing happens my cursor in cmd is going to the top and then return to it's original position and it's doing this forever, therefore each time I try a vows command in cmd I have to close the cmd to run another command).
What I'm doing bad?
thanks
NPM is great at globally installing packages and making the executable for each operating system (UNIX-ish + Windows), so proceed with the following:
npm install -g vows

Resources