First, Introduction
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.
Second, since it is not a JavaScript application, why is it called. js?
node. JS is a JavaScript-run environment. Referring to JavaScript, the first thing you think about is the daily use of the browser, modern browser contains a variety of components, including the rendering engine, JavaScript engine, etc., where the JavaScript engine is responsible for interpreting the JavaScript code in the Web page. As one of the most important languages in the Web front end, JavaScript has always been a patent for front-end engineers. However, node. JS is a back-end JavaScript runtime environment (supported systems include *nux, Windows), which means that you can write system-level or server-side JavaScript code and give it to node. js to interpret execution, simple commands similar to the following:
#node Helloworld.js
node. JS uses Google Chrome's V8 engine for good performance while also providing many system-level APIs such as file manipulation, network programming, and more. Browser-side JavaScript code is subject to a variety of security restrictions at runtime, with limited operation to the client system. In contrast, node. JS is a comprehensive background runtime that provides JavaScript with many features that other languages can implement.
< span> third, node. JS uses event-driven, asynchronous programming, designed for network services
in some traditional language network programming, we use callback functions, such as when the socket resource reaches a certain state, the registered callback function will be executed.
node. JS's design idea is event-driven, and the vast majority of the APIs it provides are event-based, asynchronous styles. Take the net module for example, where net. The socket object has the following events: Connect, data, end, timeout, drain, error, close, and so on, developers using node. js need to register corresponding callback functions according to their business logic. These callback functions are executed asynchronously, meaning that although these functions appear to be registered sequentially in the code structure, they do not depend on the order in which they appear, but instead wait for the corresponding event to fire. The important advantage of the
is that it takes advantage of system resources, that execution code does not need to be blocked waiting for some sort of operation to complete, and that limited resources can be used for other tasks. This type of design is ideal for back-end network service programming, as is the goal of node. js. In server development, concurrent request processing is a big problem, and blocking functions can lead to wasted resources and time delays. With event registration, asynchronous functions, developers can increase the utilization of resources and improve performance.
from the support modules provided by node. JS, we can see that many functions, including file operations, are executed asynchronously, which differs from traditional languages, and that in order to facilitate server development, node. JS has a particularly large network module, including HTTP, DNS, NET, UDP, HTTPS, TLS, and so on, developers can quickly build Web servers on this basis. Take simple helloworld.js for example:
var http = require (' http ');
Http.createserver (function (req, res) {
Res.writehead ($, {' Content-type ': ' Text/plain '});
Res.end (' Hello world\n ');
}). Listen (80, "127.0.0.1");
The code above builds a simple HTTP server that listens on 80 ports locally, and the server returns a "Hello World" text response with a header status code of 200 and Content-type ' value of text/plain ' for any HTTP request. From this small example, we can see a few points:
node. JS's network programming is convenient, and the module (here is HTTP) opens up an easy-to-get API interface that can be built with just a few lines of code.
Demonstrates event-driven, asynchronous programming, specifying a callback function (implemented in JavaScript's anonymous function) in the parameters of the Createserver function, which node. JS calls the callback function to process the request and respond when an HTTP request is sent. Of course, this example is relatively simple, there are not too many event registrations, and in future articles readers will see more practical examples.
Iv. features of node. JS
1, event-driven, asynchronous programming.
2, performance convincing.
3, supported programming language JavaScript.
v. node. JS and Java are server languages, the difference between the two:
(1), node. JS is faster than Java: node. JS development is fast, the efficiency of running is relatively high, but if the project is large and easy to mess, and JavaScript is not a static type language, to run to know the type error, so write more after the inevitable will appear to know the wrong But I can't find the wrong situation, so the test will have to write better and more detailed.
Java development is slow, but if the project is large and complex, it is not easy to mess with Java and manage it more than node. js Province.
(2), the front and back of node. JS is JavaScript, representing the trend of future development, while Java is now the most popular server-side programming language.
(3), node. JS is an explanatory language, and Java EE is a programming language.
If you're a front-end programmer and you don't know a dynamic programming language like PHP, Python, or Ruby, then you want to create your own service, then node. JS is a great choice. node. JS is JavaScript running on the server, and if you're familiar with JavaScript, you'll easily learn to node. js. Of course, if you're a back-end programmer and want to deploy some high-performance services, learning node. JS is also a great option.
Today, technology is being updated every day, and we cannot stop our own pace of progress. Interested partners hurry up and move on!
Why learn about node. js