What node. js is, node. JS creates an app

Source: Internet
Author: User

Simply put, node. JS is the JavaScript that runs on the server. node. JS is a platform built on the Chrome JavaScript runtime. node. JS is an event-driven I/O server-side JavaScript environment, based on the Google V8 engine, the V8 engine executes JavaScript very quickly and with great performance.

Part of the node. JS app:
    1. introducing the required module: We can use the require directive to load the node. JS module.

    2. Create server: The server can listen to the client's request, similar to Apache, Nginx and other HTTP server.

    3. receiving requests and responding to the request server is easy to create, and the client can send HTTP requests using a browser or terminal, and the server returns the response data after receiving the request.

Create a node. JS app

1. Introduction of Required Module

Use the require directive to load the HTTP module and assign the instantiated HTTP value to the variable HTTP, as shown in the following example:

var http = require ("http");

2. Create a server

Next Use the Http.createserver () method to create the server and use the Listen method to bind the port. The function uses the request, Response parameter to receive and respond to data.

 var  http = require (' http ' });     //  send response data "Hello World"  Response.End (' Hello world\n '  8888 //  terminal prints the following information  Console.log (' Server running at http://127.0.0.1:8888/'); 

Parsing the HTTP Server for node. JS:

  • The first line requests (require) node. js's own HTTP module and assigns it to the HTTP variable.
  • Next, invoke the function provided by the HTTP module: Createserver. This function returns an object that has a method called Listen, which has a numeric parameter that specifies the port number that the HTTP server listens on.

What node. js is, node. JS creates an 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.