Satinder singh
Satinder singh

Reputation: 10198

Run Hello world from node.js command prompt in windows 7

I have installed node-v0.10.13-x86.msi from nodejs.org
I have a file test.js having path (d:\BNB\test.js)

test.js:

console.log("Hello world!");

I am able to run test.js from my cmd but not from node.js command prompt refer below screenshot

From start > run > cmd (working)

enter image description here

From Node.exe (not working) enter image description here

Upvotes: 15

Views: 71566

Answers (6)

naveen kumar
naveen kumar

Reputation: 188

i believe u need to start node server from the location where your file is.

Upvotes: 0

iakwvina
iakwvina

Reputation: 83

To show the correct directory in Node.js you need to create the right path in your System: System > Advanced System Settings > Advanced > Enviroment Variables

Then in the System variables check for Variable Path.After you have installed the Node.js it should also have :(other paths); C:\Program Files\nodejs\ <-the link of Node.js directory

Click -OK-

Now if you open Command Prompt, and you go to the directory of your .js file, the 'node' (node file.js) command should work.These steps worked to my problem.

Upvotes: 1

tony
tony

Reputation: 887

We can however run tests on the command prompt once we have node.js installed.

On the Windows command prompt type node ENTER

Then we can run our JavaScript code tests just like we do on any other Console:

console.log("Hello World!");

It replies with "Hello World!"

Upvotes: 3

moka
moka

Reputation: 23047

Node.exe is application that can be used to run code from file, or to be ran by it self that way it will behave like live-terminal.
Once you run node.exe like you did in second example, you will end up in node environment and everything from there is not cmd at all, but JS.

If you type: node example.js that will call node environment and will execute file in that environment.

Although, running node.exe is the same as typing node in cmd.

Upvotes: 14

salek
salek

Reputation: 444

in node REPL you could type

require('d:\\BNB\\test')

that shuold run your file..

Upvotes: 5

I&#39;m Poor
I&#39;m Poor

Reputation: 123

You are trying to execute the program from the node prompt. You don't do that. You just run the node terminal. It sets up a bunch of variables for you. Just run it like you do in the ordinary windows shell.

Upvotes: 4

Related Questions