1

I have downloaded Node.js from their site in my windows xp os. I have installed it through the microsoft installer. I didn't know how to write my first application, where to save them and how to execute them in Windows. I have got a node.js command prompt but I can't use it. I have searched a lot but there is only instruction for linux and mac. I didn't find any suitable tutorial or example that I can start a node application from scratch.

If anybody can put some documentation or steps or any such tutorial where I can get help of this, it will be great for me.

JB.
  • 40,344
  • 12
  • 79
  • 106
Mrinmoy Ghoshal
  • 2,804
  • 1
  • 19
  • 17
  • 1
    I imagine if you have a node.js command prompt then it would be as simple as creating a js based file in a directory, then navigating to that directory using the node.js command prompt and then typing node . – Simon H Dec 13 '12 at 07:04
  • ok I am trying it @ZeSimon – Mrinmoy Ghoshal Dec 13 '12 at 07:05
  • 1
    If you search Google exactly for `node.js server windows`, there's several articles on how to run it with a server. Note, however, that most of what I saw reference IIS, which I have no idea if and how you can get that installed. But you need a server running that can handle sending requests to your node.js runtime. Apache, nginx, lighthttp, and IIS are most typical (Tomcat?). – Jared Farrish Dec 13 '12 at 07:12
  • Here's a [tutorial](http://thecodinghumanist.com/blog/archives/2011/4/23/getting-started-with-node-js-on-windows), using node.js to create a server. Seems interesting. – Jared Farrish Dec 13 '12 at 07:14

2 Answers2

8

As this blog entry by Eric, it is ridiculously easy to get a node.js server setup and responding to requests on 127.0.0.1:#port#.

Really easy. I just did it all in... Longer than write this text.

  1. Download an OS-appropriate node.js1: http://nodejs.org/

  2. Now, create a .txt (plaintext) file in the same folder as your node.exe and rename that to server.js.

  3. Put this Javascript in that file:

    var http = require('http');
    
    http.createServer(function (request, response) {
        console.log('request starting...');
    
        response.writeHead(200, { 'Content-Type': 'text/html' });
    
        var html = '<p>Hello World!</p>';
    
        response.end(html, 'utf-8');
    }).listen(8125);
    
    console.log('Server running at http://127.0.0.1:8125/');
    
  4. Open a cmd.exe and cd c:\path\to\the\node\executable, where node.exe resides.

  5. From there, run:

    node server.js
    

    You should see it say:

    Server running at http://127.0.0.1:8125
    
  6. Open a browser and put http://127.0.0.1:8125/ in the address bar.

    You should see it say:

    Hello World!
    

That's it. That's pretty easy. The proverbial Hello World! in 15 seconds or less. Now how to get it to parse a Javascript file and return that output instead of simple HTML...


1. Note, I got the executable, node.exe, made a folder somewhere, put the executable in that folder. No installer. Works like a charm.

Elamurugan
  • 3,204
  • 13
  • 59
  • 104
Jared Farrish
  • 48,585
  • 17
  • 95
  • 104
  • Its now running. But When I closed the command prompt. Server is not running anymore. Is there any way to run it altime? – Mrinmoy Ghoshal Dec 13 '12 at 09:01
  • Run it as a service. See the answers for [this question](http://stackoverflow.com/questions/10547974/how-to-install-node-js-as-windows-service). – Jared Farrish Dec 13 '12 at 09:03
  • @JaredFarrish - regarding #4, I added node path in system variables of my Windows Server 2008 R2 and now its working from anywhere by passing this from cmd.exe _node.exe "C:\nodejs-stuff\Server.js"_ – Gaurav Arora Jun 05 '14 at 20:51
0

Here is the new way develop node.js app with Windows Environments and Visual Studio >= 2012 https://nodejstools.codeplex.com/

Gencebay
  • 481
  • 2
  • 8
  • 15
  • 1
    Note that [link-only answers are discouraged](http://meta.stackoverflow.com/tags/link-only-answers/info), SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference. – kleopatra Dec 15 '13 at 12:25