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.

4
  • 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 <your_script_name>. Commented Dec 13, 2012 at 7:04
  • ok I am trying it @ZeSimon Commented Dec 13, 2012 at 7: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?). Commented Dec 13, 2012 at 7:12
  • Here's a tutorial, using node.js to create a server. Seems interesting. Commented Dec 13, 2012 at 7:14

2 Answers 2

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.

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

3 Comments

Its now running. But When I closed the command prompt. Server is not running anymore. Is there any way to run it altime?
Run it as a service. See the answers for this question.
@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"
0

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

1 Comment

Note that link-only answers are discouraged, 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.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.