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:
introducing the required module: We can use the require directive to load the node. JS module.
Create server: The server can listen to the client's request, similar to Apache, Nginx and other HTTP server.
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