3

Just getting started with node.js. I've a Windows PC. I went to nodejs.org and downloaded the nodejs.msi for Windows then, I saw a folder in programfilesx86.

How do i write and compile my helloworld program?

I guess, I have to use the command prompt. I even created a file hello.js but i don't know where it goes or how to execute it.

Any inputs on this will be appreciated.

3 Answers 3

6

Go to the command prompt (> Run > cmd), which is the Windows terminal.

There type node -v to see if Node is responding ok (it should display the version installed).

After that navigate to the folder containing your 'hello world' example.

For ex if you hello.js is in C:\ then:

cd C:
node hello.js

That should work.

Sign up to request clarification or add additional context in comments.

5 Comments

:It is not responding.what should i set in environment variable.
@user1051322: You'll need to include node's directory in your PATH variable, though I though the Windows installer took care of that.
Ed S. the latest .msi of Node takes care of that for you.
As of June 2012 the windows installer still has its rough edges: it requires you to restart your windows session for the PATH changes to take effect, it doesnt let you choose your installation directory, etc
As of 2013.11 the windows installer is much better - PATH changes are often (not always) available in the same shell. A number of npm packages require run-as-Administrator to install successfully, though.
2

After restarting my system,this worked bcoz it is windows.In windows,you've to restart after installing any thing.

2 Comments

Thats a common misconception. Usually if you know enough you don't need to reboot, restarting an application or service is enough. Chances are good a service needed starting or the command prompt needed reopening due to environment variables needing to be picked up again.
@Phil Hannent:Which service should i restart?
0

Alternative is to use IDE like Enide Studio http://sf.net/p/nodeclipse/

Instead of typing in command prompt, just right-click any .js file and select Run As -> Node application, see output in console View. All in one windows, no need switch between. Integrated debugger and JSHint.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.