简体   繁体   中英

How to write first application in Node.js in Windows Environment?

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.

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.js 1 : 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.

这是使用Windows环境和Visual Studio> = 2012 https://nodejstools.codeplex.com/开发node.js应用程序的新方法

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM