In fact, it does not mean that you must learn node, but for better development in the workplace, especially to learn more advanced programming thinking, it is necessary to learn node.
The following is a detailed explanation of the necessity of learning node[Recommendation: node.js video tutorial]
1.node.js is the most fundamental The ability is to enable js to run without the browser. If you learn node well, you can no longer be a "pure front-end"
2. Learning nodejs is the basis for front-end engineering (NodeJS Stream)
3. Learn node well , you can write server-side APIs to implement independent development projects
4. As the middle layer (extended question: What is the middle layer?)
The middle layer (BFF) is also called the application layer and is a service in the architecture The main functions between the layer (Java) and the client:
- Receive client requests
- Render HTML pages
- Bigpipe, Comet, Socket
- Merge interface request
- Route customization
- Data caching
Now why is it said that the front-end often needs to write its own API?
1. Classic two-tier structure: front-end server
2. Three-tier structure: front-end and back-end server (the structure used by current medium and large projects)
Three layers The server side of the structure is only responsible for operating the database, managing data
, and returning the data to the backend. It is basically pure data and does not include data services
The backend is the so-called middle layer. If the frontend is developed, then Prefer nodejs because the learning cost is the lowest for the front end.
If your career position is to be a pure front-end for a lifetime, then you don’t need to learn nodejs. However, in fact, it is difficult to be a pure front-end for a lifetime. Generally, by the age of 35, the ability you have is only "moving bricks" , then the value in the workplace will be lower and lower.
CTO is often served by server-side engineers
Reason:
1. The technical architecture of the entire company needs to be designed
2. The problem needs to be considered from a global perspective
3. Need to control the company’s most important asset: data (whoever controls the data has the right to speak)
Learning node well does not mean that you can be a CTO, but at least it can greatly improve our front-end workplace status.
Technically speaking, it is a very fulfilling thing to use your own abilities to independently complete a project or product.
Even if all the previous reasons are eliminated, as a pure front-end, learning node also has great benefits. It can cultivate our programming thinking and expand our perspective on thinking about problems.
The advantages, disadvantages and applicable scenarios of NodeJs
The two major characteristics of NodeJs: event-driven, non-blocking I/O
So the two biggest advantages of NodeJs
1. Handle high concurrency. Compared with other back-end languages, each connection emits an event (Event) that runs in the NodeJS engine process and puts it into the event queue instead of generating it for each connection. A new OS thread (and allocate some supporting memory for it)
2. I/O-intensive applications
Because of the single-threaded nature of JavaScript, NodeJs is not suitable for CPU-intensive applications; CPU-intensive applications The main challenges brought to Node are: due to the single-threaded 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;
Applicable scenarios for NodeJs:
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. It only needs to request the API and organize the data to return. 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.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 The other one is on the server side and is responsible for generating and splicing pages.Applications with a large number of Ajax requests
For example, personalized applications, each user sees a different page, the cache is invalid, and Ajax needs to be initiated when the page is loaded. Request, NodeJS can respond to a large number 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