Application of Node.js in the big front end

The emergence of Node has brought new vitality to front-end development after the emergence of Ajax, and has qualitatively improved the efficiency and performance of development. This article briefly summarizes the status and application of Node in the development of large front-ends.

Basic concepts of Node

  • JavaScript not running in the browser
  • A platform based on Chrome JavaScript runtime
  • An event-driven I/O server-side JavaScript environment based on Google’s V8 engine

Application of Node in the big front end

Insert picture description here

It can be seen from the figure that the application of Node is very extensive, of which the most commonly used are engineering, automation and npm package management. In addition, in a broad sense, applications include js running on the non-browser side, including front-end environment construction, cloud construction, services, middleware, and node.js application scenarios. Specific applications include front-end tool chain level, npm, engineering related, complete separation of front-end and back-end, and server.

1. Front-end tool chain: babel, webpack, eslint, jest

Insert picture description here

2. npm: own commands to manage npm packages and execute node files

Insert picture description here

Features: The npm package as a whole is a code abstraction that has common applications, including logic abstraction, component abstraction, and function abstraction

3. Engineering related

The establishment of a 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 technology from the era of slash and burn. Front-end engineering relies on the aforementioned webpack, gulp, babel, eslint, etc. The complete scaffolding system not only includes client capabilities, but also includes automatic construction (such as jenkins) and command-line release functions

Four, desktop application development

Node.js makes it possible to develop desktop applications using js. Electron is currently a more popular desktop application development tool. It combines nodejs and chromium to allow users to call node.js functions and use almost all nodejs communities. In the module. Web applications are very popular nowadays, 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 to make front-end engineering unified and simplified.

Five, the front and rear ends are completely separated

The front-end application is separated from the server-side code and deployed independently on the service provided by node.js. There are two rendering methods:

    One is to use conventional rendering to generate html code in the browser; the
    other is to use server-side rendering (ssr), which is similar to the previous method of java generating html code, but now ssr and real services It doesn’t matter much on the end, ssr is the way to render on the node.

Full stack development based on large projects

    Based on the independent deployment of the front-end, logic codes such as data processing, interface proxy, and terminal adaptation are added to the node side, which greatly enhances the front-end scalability and performance. Common full-stack frameworks include egg, midway, etc.

The need for complete separation of front and rear ends

  1. In the development process, some responsibilities are unclear. The separation of front-end and back-end means that the front-end no longer depends on the back-end. The back-end can focus on the model layer, and the front-end can focus on the view and controller.

  2. In web performance optimization, the optimization work that the front-end can do has great limitations. Many optimizations must be completed on the basis of coordination with the back-end. Node.js as the middle layer allows the front-end to have sufficient optimization decisions.

  3. The front-end can be based on business, adjust the front-end architecture, and integrate different technology stacks

Applicability of complete separation of front and rear ends

Suitable for teams with certain technical support, and cannot be separated for the sake of separation

Front-end independent deployment extension

  1. Realize cloud construction based on node, get through gitlab, access control, log, etc.;
  2. Automatic code verification and risk monitoring before release;
  3. Deploy multiple release environments;
  4. Release in grayscale to achieve rollback;
  5. Realize the cdn system;
  6. Realize buried point and alarm monitoring system.

Six, Node as the server

In general, we use node as the middle layer, and in some small projects, node can also be used as a pure back-end development language. Node is a single-threaded, asynchronous I/O operation, and the core is a time loop mechanism, suitable for high I/O, non-computing-intensive services. Node can run multiple processes, which can increase the utilization of multi-core CPUs for building clusters. In addition, Node is also used to implement functions such as performance monitoring, log statistics, routing analysis, etc.
Insert picture description here

Node sum serverless

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

As a new type of Internet architecture, it directly or indirectly promotes the development of cloud computing. From AWS Lambda to Alibaba Cloud Function Computing, Serverless has been singing all the way, and at the same time, serverless-based lightweight computing has begun to log on to the cloud computing stage.

The core of Serverless is Faas, function as a service, which solves the problems and pain points of traditional BFF, such as high resource cost, high operation and maintenance cost, high development cost, and difficulty in adapting to rapid changes in demand, allowing developers to focus more on business logic and other underlying layers Resources and operation and maintenance work have been fully encapsulated.

Node implements serverless

Use the Serverless framework to build the Faas environment. The ServerLess framework is a CLI tool written in Node.js. Developers can deploy a complete and usable Serverless application architecture without paying attention to the underlying resources. Developers only need to write related functions according to the business and deploy them to the It can be on the cloud computing platform.

Guess you like

Origin blog.csdn.net/weixin_40599109/article/details/108148686