Author: Front-end 361

The original address: zhuanlan.zhihu.com/p/121055042

Node has been used for a long time and has been widely used. It seems that node exists wherever there is a front end. So let’s think about a question: what is node used for? This paper explains the problem from five aspects. This article can not only apply scenario analysis, but can also be used as a route to node.js advanced progression, and see what you still need to learn.

We know that the emergence of Node, so that the front-end development after Ajax, has a new look, in the development efficiency, performance and other aspects have a qualitative improvement. Generalization is always an important part of knowledge development, and this article provides an introductory summary of node applications with a lot of references. After reading this article, I hope to have a clear understanding of node’s place and use in the big front end.

Let’s start with a picture:

What Node brings:

It can be seen from the figure that Node has a wide range of applications, and the most commonly used ones are engineering, automation and NPM

Basic Concepts of Node

  • 1. Javascript that doesn’t run in the browser

  • 2, a platform built on the Chrome JavaScript runtime

  • An event-driven I/O server-side JavaScript environment based on Google’s V8 engine

Next, take a closer look at the use of Node.js in the big front end.

Generalized application

Js running in non-browser side, including front-end environment building, cloud building, services, middleware, have Node.js application scenarios

The specific application

First, front-end tool chain level

Second, the NPM

Three, engineering related

4. The front and rear ends are completely separated

Fifth, the server

First, front-end tool chain

Specific uses of Babel, Webpack, ESLint, jest, etc., are not discussed

Second, the NPM

1, own command

Used to manage NPM packages and execute node files

2, NPM package

Features: The NPM package as a whole is a common class of code abstractions, including logical abstractions, component abstractions, and function abstractions

Three, engineering related

The establishment of front-end environment is one of the most valuable applications of Node.js in front-end development. The emergence of Node makes front-end development enter the era of science and technology from the slash-and-burn era. Front-end engineering relies on the aforementioned webpack, gulp, Babel, eslint etc., complete scaffolding system in addition to the ability of the client, including an automated build (Jenkins, for example), the function of the command line publish

Developing desktop Applications

Node.js makes it possible to develop desktop applications using JS. Electron is a popular desktop application development tool at present. Combining NodeJS with Chromium, it allows users to call node.js functions. You can use almost any module in the NodeJS community.

At present, web applications are very popular, desktop applications seem to be forgotten, but desktop applications also have certain advantages, for example, in the field of front-end engineering, desktop applications can be used as a unified GUI integration tool, so that front-end engineering becomes unified and simplified.

Meaning of front-end engineering

4. The front and rear ends are completely separated

1. The front-end application is independently deployed on the service provided by Node.js without the server-side code

There are two rendering methods, one is the use of regular rendering, in the browser to generate HTML code;

The other option is to use server rendering (SSR), which is similar to the way Java used to generate HTML code, but SSR doesn’t have much to do with the real server. SSR is the way to render on the Node side

2. Full-stack development based on large projects

On the basis of independent front-end deployment, node end is added with data processing, interface proxy, terminal adaptation and other logical codes, which greatly enhances front-end scalability and performance. Common full-stack frameworks are Egg, Midway, etc

The need for complete separation of front and rear ends

1. In the development process, some responsibilities are not clearly divided. The separation of front and back ends means that the front end is no longer dependent on the back end, and the back end can focus on the Model layer, while the front end focuses on view and Controller

2. In web performance optimization, there are great limitations in the optimization work that can be done by the front end. Many optimizations need to be completed on the basis of the coordination of the back end

3, the front-end can be adjusted based on business, front-end architecture, integration of different technology stacks

Applicability of complete separation of front and rear ends

Suitable for a certain technical support of the team, not for the sake of separation and separation

Front-end independent deployment expansion

Node serves as the server

The Node and serverless

Serverless began to emerge in China in 2019. It has not been applied on a large scale yet, but Serverless is an inevitable trend.

As a new type of Internet architecture, it has directly or indirectly promoted the development of cloud computing. From AWS Lambda to Ali Cloud function computing, Serverless has been enjoying great success all the way. Meanwhile, lightweight computing based on Serverless has started to enter the stage of cloud computing.

The core of Serverless is Faas, function as service, which solves the problems and pain points of traditional BFF, such as high cost of resources, high cost of operation and maintenance, high cost of development, and difficulty in adapting to the rapid change of demand, so that developers can focus more on business logic, and other underlying resources and operation and maintenance work have been all encapsulated.

The Node implementation serverless

Faas environment is built with Serverless framework. Serverless framework is a CLI tool written using Node.js. Developers can deploy a complete and available Serverless application architecture without paying attention to the underlying resources

After that, developers only need to write relevant functions according to the business and deploy them on the cloud computing platform.

The serverLess platform is already in use

conclusion

This article can not only apply scenario analysis, can completely treat it as node.js advanced when the route, look at those you still need to learn, I hope to help friends.

If you like me, you can search the public account [aurora training Camp] to know more dry goods.

At the same time, I can also add my VX: Jgxiaokeai to the tech chat group to discuss the front-end issues with the tech giants

! [](https://p1-jj.byteimg.com/tos-cn-i-t2oaga2asx/gold-user-assets/2020/7/29/173986bbf3bf8ee6~tplv-t2oaga2asx-image.image )