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.

Christopher Scott
  • 2,383
  • 2
  • 25
  • 23

3 Answers3

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.

alessioalex
  • 62,577
  • 16
  • 155
  • 122
  • :It is not responding.what should i set in environment variable. –  Dec 01 '11 at 18:08
  • @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. Dec 01 '11 at 18:27
  • Ed S. the latest .msi of Node takes care of that for you. – alessioalex Dec 01 '11 at 22:04
  • 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 – leonbloy Jun 29 '12 at 11:18
  • 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. – Michael Paulukonis Nov 22 '13 at 13:50
2

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

  • 3
    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 Dec 02 '11 at 08:39
  • @Phil Hannent:Which service should i restart? –  Dec 02 '11 at 09:33
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.

Paul Verest
  • 60,022
  • 51
  • 208
  • 332