Home > Web Front-end > JS Tutorial > What is node.js suitable for? What are the benefits of using node.js?

What is node.js suitable for? What are the benefits of using node.js?

寻∝梦
Release: 2018-09-05 15:29:22
Original
8219 people have browsed it

This article mainly talks about the suitable direction of node.js. What is node.js suitable for? What are the benefits of node.js? Please see the article for specific details.

1. Let’s first talk about what node.js is suitable for:

First of all, nodeJs is the cornerstone of the front-end full stack, and its application scenarios have evolved from the front-end The scaffolding and auxiliary tools of tools have developed into the API middle layer, agent layer, and professional back-end development.

The most valuable of these is the api middle layer. The big trend now is that more and more business is being pushed to the front end, and the back end is focused on only providing services. A very typical and common work scenario is that when the front-end and back-end collaborate, sometimes the front-end needs to wait for the back-end interface due to different progress.

At this time, the middle layer application of nodeJs can solve this problem very well. Through nodeJs, the front end can agree on the format of the data, customize its own interface according to the needs of the front end, encapsulate CRUD operations on the database, create its own proxy and gateway servers, etc. In the past, you could only wait for the backend to do these things, but now you can do it yourself through the nodeJs frontend, which makes the work process more controllable.

Of course, this also puts forward higher requirements for front-end developers. At least the shortcomings in database, architectural design, system structure, and network applications need to be slowly filled.

It is said that I am not sure. NodeJs was originally developed for the back-end, but the Java language was chosen for simplicity, asynchronousness, and large concurrency. By mistake, it was discovered by the front-end and carried forward.

So doing nodeJs on the front end will inevitably erode the back end, and the development structure and technology stack of the back end are already very complete, so the back end is generally unwilling to change, so many times the resistance to nodeJs actually comes from the back end. Extremely conservative. Of course, this makes sense, because the backend is mainly services, data, and underlying applications. These things require stability and security, and there are some historical issues, so they don't like new things.

So at this stage, many nodeJs applications are bridges between the front-end and the back-end. Generally speaking, new companies, startups, and incubation projects without any historical baggage are more willing to use nodeJs because it is fast and efficient.

Nowadays, basically all front-end applications have the shadow of nodeJs, such as React, vue, angular, etc. Its application scenarios and job market are also very large, so learning nodeJs is not about what you can do. But it gives you one more space to display. (If you want to know more about node.js, come to the node.js video tutorial column on the PHP Chinese website)

2. Now let’s talk about using node.js Benefits:

As you saw earlier, Node is ideal for situations where you anticipate potentially high traffic before responding to the client, but the required server-side logic and processing is not There must be a lot. We have summarized three benefits of Node, which can also be said to be typical examples of outstanding performance:

1.RESTful API

The Web service that provides RESTful API receives several parameters, parses them, assembles a response, and returns a response (usually less text) to the user. This is an ideal situation for Node because you can build it to handle tens of thousands of connections. It still doesn't require a lot of logic; it essentially just looks up some values ​​from some database and composes them into a response. Since responses are small amounts of text and inbound requests are small amounts of text, the traffic is not high and a single machine can handle the API needs of even the busiest companies.

2.Twitter Queue

Imagine a company like Twitter that has to receive tweets and write them to a database. In reality, with almost thousands of tweets arriving per second, it is impossible for the database to handle the number of writes required during peak hours in a timely manner. Node becomes an important part of the solution to this problem. As you can see, Node can handle tens of thousands of inbound tweets. It quickly and easily writes them to an in-memory queuing mechanism (such as memcached), from where a separate process can write them to the database. Node's role here is to quickly collect tweets and pass this information to another process responsible for writing. Imagine an alternative design (where a regular PHP server would try to handle writes to the database itself): each tweet would cause a short delay in being written to the database because the database call is blocking the channel. A machine designed this way might only be able to handle 2000 inbound tweets per second due to database latency. Processing 1 million tweets per second would require 500 servers. Instead, Node handles each connection without blocking the channel, allowing it to capture as many tweets as possible. A Node machine that can handle 50,000 tweets requires only 20 servers.

3.Video Game Statistics

If you've played the game Call of Duty online, you'll immediately realize something when you look at the game's statistics: To generate that level of statistics, a huge amount of information must be tracked. In this way, if there are millions of players playing online at the same time, and they are in different positions in the game, a huge amount of information can be generated very quickly. Node is a great solution for this scenario because it ingests the data generated by the game, performs minimal merging of the data, and then queues the data so that it can be written to the database. Using an entire server to track how many bullets a player fires in a game seems silly, and if you use a server like Apache, there may be some useful limitations; but instead, if you use a dedicated server to track all statistics for a game Data, as you would do with a server running Node, that seems like a smart move.

The above is an introduction to the use of node.js and the benefits of node.js (if you want to see more content, go to the node.js Chinese Reference Manual column on the PHP Chinese website), there are If you have any questions, you can ask below

[Editor’s recommendation]

How to use node.js? Let’s talk about the application process of node.js in a simple way:

What does node.js do? Introduction to 10 application scenarios of node.js

The above is the detailed content of What is node.js suitable for? What are the benefits of using node.js?. For more information, please follow other related articles on 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