Home  >  Article  >  Web Front-end  >  What are the disadvantages of nodejs

What are the disadvantages of nodejs

青灯夜游
青灯夜游Original
2021-11-11 15:22:143924browse

Disadvantages of nodejs: 1. Not suitable for CPU-intensive applications; 2. Only supports single-core CPU and cannot fully utilize the CPU; 3. Low reliability; 4. The quality of the open source component library is uneven and updates quickly , downwardly incompatible; 5. Debugging is inconvenient, and there is no stack trace for errors.

What are the disadvantages of nodejs

The operating environment of this tutorial: windows7 system, nodejs version 12.19.0, Dell G3 computer.

Node.js is essentially a JavaScript runtime environment.

Node.js is a platform built on the Chrome JavaScript runtime, used to easily build web applications with fast response speed and easy expansion. Node.js uses an event-driven, non-blocking I/O model to be lightweight and efficient, making it ideal for running data-intensive real-time applications on distributed devices.

Disadvantages of nodejs:

1. Not suitable for CPU-intensive applications;

The main challenges that CPU-intensive applications bring to Node are: Due to the single-thread nature of JavaScript, if there are long-running calculations (such as large loops), the CPU time slice will not be released, making subsequent I/O unable to be initiated;

  • Solution Solution: Decompose large computing tasks into multiple small tasks so that the computing can be released in a timely manner without blocking the initiation of I/O calls;

#2. Only supports single-core CPU and cannot be fully utilized CPU

3. Low reliability. Once a certain link in the code crashes, the entire system crashes

  • Cause: single process, single thread

4. The quality of the open source component library is uneven, it updates quickly, and it is not backward compatible

5. Debugging is inconvenient, and there is no stack trace for errors

Suitable for NodeJS Scenario

1. RESTful API

This is the most ideal application scenario for NodeJS. It can handle tens of thousands of connections. It does not have much logic itself. It only needs to request the API and organize the data. Just go back. 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. Unify the UI layer of Web applications

The current MVC architecture, in a sense, Web development has two UI layers, one is in the browser we finally see , and the other one is on the server side, responsible for generating and splicing pages.

I won’t discuss whether this architecture is good or bad, but there is another practice, the service-oriented architecture, which can better separate the dependencies of the front and back ends. If all key business logic is encapsulated into REST calls, it means that the upper layer only needs to consider how to use these REST interfaces to build specific applications. Those back-end programmers don't care about how specific data is passed from one page to another. They don't care whether user data updates are obtained asynchronously through Ajax or by refreshing the page.

3. Applications with a large number of Ajax requests

For example, personalized applications, each user sees a different page, the cache is invalid, and Ajax requests need to be initiated when the page is loaded. NodeJS can Respond to large numbers of concurrent requests. In short, NodeJS is suitable for use in scenarios with high concurrency, I/O intensive, and a small amount of business logic.

[Recommended learning: "nodejs tutorial"]

The above is the detailed content of What are the disadvantages of nodejs. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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