Node. js I understand

Source: Internet
Author: User

I have seen many colleagues write blogs about node. js and I will learn from them. As a beginner, my understanding is summarized as follows:

    • Node is a command line tool.
    • Node can enableCodeRun on the server.
    • The JS Code can be executed in V8.
    • Node provides a set of APIs to access networks and file systems.

1. node is just a tool that provides JS execution on the server, such as Java, Ruby, and PHP. Do not use node to solve all things.

2. node runs in parallel. You can perform several tasks at the same time ),Obviously, because node executes multiple tasks in parallel, it is obviously multi-threaded. Next we will learn about the node source to see how it achieves this mechanism of parallel operation.

For example, 1, 2:

Figure 1

Figure 2

The above code executes a task for the node to read a write, and the callback will be triggered once the processing ends. Note that only one callback is triggered at a time until the callback is executed. Other Callbacks are waiting in queue. The callback is not executed in the order of asynchronous execution. Figure 2 is just one. You can write a small code to understand it.

3. The single thread/event loop mechanism prevents node from worrying that the Code will simultaneously access the same data structure. (Excerpt from the original node document)

PS: but in practice, it is obvious that node supports multithreading. Is it implemented through thread security? This requires in-depth understanding.

4. What are the advantages of node?

    • Execution efficiency: In Web applications, waiting for DB query results is a time point. Through the parallel processing mechanism, it can execute all the queries at a time (asynchronous ), save the execution time of the slowest query.
    • Based on JS, The frontend and backend share code, all written in Js.
    • The execution efficiency of V8, as mentioned in node promotion, may be close to the execution efficiency of local system I/O.

In addition to the first point, you can verify it by yourself. The last two points are described on the Internet. The second point is understandable. The third point is a bit of propaganda. You can find a test tool and try it. Other advantages are welcomed.

5. Under what circumstances is node suitable for use?

After learning about node, you will certainly find a place on the project where you can use it. When discussing technical implementation, you will want to plug it in, otherwise, it's not just a matter of White. ^-^ first of all, I think it is important to understand low response time and high concurrency first? What is the scale of the project? Obviously, if you want to use node in a large project, there will be more issues to consider, such as library resources and bugs in the node itself, which need to be carefully evaluated.

6. Summary of sites currently using node:

Http://cnodejs.org

Http://www.plurk.com/top

I will not post it abroad. Thanks to my motherland ~

 

At the end of this article, through the study of node, we can see that node has an approximate 80% similarity. For example, a Java-based Server framework (commercial level) that will be very popular in ), the source code of the Framework is Java that supports JavaScript Execution as scripts. It also has a parallel processing mechanism, and its implementation principles are basically the same. The author is an entry-level beginner of node. The above content is limited to the level of deficiency. You are welcome to correct it. I will summarize it and modify it. Please forgive me for its colloquial style. 

 

When reprinting, please indicate the source of this article: www.cnblogs.com/tmywu

Author: old fish 678

Mail: tommywu23@126.com

 

 

 

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.