The first node. JS app

Source: Internet
Author: User

创建Node.js应用前,我们要知道Node.js是分模块的,其中 "http模块" 是其内置模块可以直接使用(先这么记着就行,不需要深究,以后就明白了)。新建一server.js文件,其内容为:
//Request HTTP module to gain access to the networkvarHTTP =require(' http '); Http.createserver ( function(request, Response){    //Send HTTP header    //HTTP status value: 200:ok    //Content type: Text/plain    //join: Charset=utf-8 can prevent Chinese garbledResponse.writehead ( $, {' Content-type ':' Text/plain;charset=utf-8 '}) ;//Send response data "Hello World"Response.End (' Hello world\n Chinese is garbled ') ;}). Listen8888) ;//Monitor 8888 Port//Terminal printing informationConsole.log (' Server running at http://127.0.0.1:8888/') ;
命令行输入node server.js,显示如下:

浏览器输入:http://127.0.0.1:8888/ 显示如下:

好了,第一个node.js应用到此完成。

The first node. JS app

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.