最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to write first application in Node.js in Windows Environment? - Stack Overflow

programmeradmin5浏览0评论

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 mand 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.

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 mand 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.

Share Improve this question edited Nov 27, 2013 at 14:51 JB. 42.2k13 gold badges82 silver badges109 bronze badges asked Dec 13, 2012 at 7:01 Mrinmoy GhoshalMrinmoy Ghoshal 2,8341 gold badge20 silver badges17 bronze badges 4
  • 1 I imagine if you have a node.js mand 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 mand prompt and then typing node <your_script_name>. – Simon H Commented Dec 13, 2012 at 7:04
  • ok I am trying it @ZeSimon – Mrinmoy Ghoshal 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?). – Jared Farrish Commented Dec 13, 2012 at 7:12
  • Here's a tutorial, using node.js to create a server. Seems interesting. – Jared Farrish Commented Dec 13, 2012 at 7:14
Add a ment  | 

2 Answers 2

Reset to default 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/

  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.

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

发布评论

评论列表(0)

  1. 暂无评论