Home > Web Front-end > JS Tutorial > Detailed explanation of the characteristics of Node.js

Detailed explanation of the characteristics of Node.js

高洛峰
Release: 2017-02-04 10:14:25
Original
1239 people have browsed it

Node.js is a Java running platform based on the Chrome v8 engine, used to build web applications with fast response speed and easy expansion. This article shares with you some features of Node.js. I hope it will be helpful for everyone to learn Node.js.

Asynchronous I/O

Here, let’s explain in detail:

What does asynchronous mean?

For example, your dad wants to call you today Do something, such as cooking, washing clothes, sweeping the floor, boiling water, and a series of other things. So, as far as you are concerned, you have to finish one thing one by one before you can move on to the next thing. For example, do you boil the water and then sweep the floor? After sweeping the floor, then cook. After cooking, you may do other things. Then we call this process a synchronization process. When you do one thing, you have to wait, and then do another thing after waiting. So at this time, if we know how to arrange our time reasonably, we can do this: when we are boiling water, we can sweep the floor, because we don’t need to guard the boiling water! Just put the water in or light it. Then we can go do other things. For example, we can do a series of things like sweeping the floor or doing laundry. So, after doing the same thing, the time we need to spend is different. If you use the latter method, it may take less time and be more efficient. If you use the previous synchronization method, its efficiency will be even lower. So, we call this latter thing an asynchronous operation.

Events and callbacks

If you do things asynchronously, it will be very efficient, but you can only do one thing at the same time. For example, when you are boiling water, you are not required to stay there. But after you sweep the floor, how do I know when your water is boiling? (After this is done, how do I know?)

So we can think about it and put a small speaker on the kettle. When the water boils, steam will emit. , when the steam blows the horn, we will know that the thing is done, the water is boiling, and we can continue to do the things after the water is boiled.

This event and callback is: after the water is boiled, it will notify you in the form of an event (I have done this, you can fill the water).

What does callback mean?

When its event occurs, it will notify you. Then the process of filling water is a callback (that is, processing this process). The result after processing the boiled water

Single thread

This is a major feature of node.js. It can develop efficient background applications (network applications)

What is single-threaded

Let’s still use the example just now. Your dad asks you to do many things. If you don’t know how to arrange your time reasonably, you can only use synchronization; then when synchronizing, you may think like this: I asked a few of my friends to help me do this ( Call two or three friends). One helps me boil water, one helps me sweep the floor, and one helps me cook. If you do this, there will be multiple people helping you do things at the same time. (We call this kind of operation multi-threaded operation, that is, multiple people are doing things at the same time)

Multi-threaded operation has a disadvantage, that is, you ask these friends to help you do things. , you must reward them, then you will definitely spend some of your pocket money, and you must buy something delicious to reward them. So, if you don't want to spend your money, but you want to get things done, what should you do? You can only do it in the asynchronous way we just did, that is, you do it alone. What should we do to improve efficiency? When I do this thing, I also want to do other things at the same time, then this is a single thread (that is, one person does things).

Cross-platform

Currently our node.js can run on mac systems, Windows and Linux. It has been developed and the corresponding operating environment has been developed.

The above is the entire content of this article. I hope that the content of this article can bring some help to everyone's study or work. I also hope to support the PHP Chinese website!

For more detailed explanations of the characteristics of Node.js and related articles, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template