Node. js entry-1. Our first service

Source: Internet
Author: User

From today on, I will start a topic on node. JS, which is my summary of reading "node: Up and running. The first lesson is about node. js installation, development tools, and how to create our first service: Hello word.

 

Window platform node. js installation is very simple, everyone to the http://nodejs.org/download the installation file, directly install it.

We recommend that you use webstorm for development tools. The support for multiple node. JS is quite good. You can read this blog post http://www.cnblogs.com/softlover/archive/2012/08/19/2646265.htmlto find out how to install the software.

We use webstorm to create a project named nodejs.

Create a file named helloworld. js under the project. Write code:

var http=require('http');http.createServer(function(req,res){    res.writeHead(200,{'Content-Type':'text/plain'});    res.end('hello\n');}).listen(8124,'127.0.0.1');console.log('Server running at http://127.0.0.1:8124/');

Next, run node. JS, click the Start menu, select all programs, find node. js (x86), and run node. js command prompt ]. Run the following command on the command line:

node d:/workspace/nodejs/helloworld.js

Here, 'node' is the command, and 'd:/workspace/nodejs/helloworld. js' is the file address you created. When you press enter, the following result is displayed, indicating that your code is running normally and the node. js server is running properly.

Or you can directly use the webstorm debugging tool.

 

 

Open the browser and enter http: // 127.0.0.1: 8124/to view the running result.

  

In Windows 7, the command cannot be executed when the Telnet command is used in the Command window. The prompt "'telnet 'is not an internal or external command, or a program or batch file that can be run" is displayed ".

Cause Analysis: Vista and Windows 7 have telnet, but are not installed by default.

Solution: Control Panel | program and function | enable and disable the WINDOWS function, and select Telnet client. Are you sure you want to save it.

Well, today's example ends.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.