This article will talk about the basic knowledge points of node, and summarize and share some nodejs knowledge that the front-end needs to know. I hope it will be helpful to everyone!
Whether it is front-end development or back-end development, I personally believe that you should not be limited to your own field. Only by breaking through the comfort zone can you improve. Although it can make perfect, but We also need to know that learning without thinking will lead to confusion, so it is necessary to understand the server-side knowledge that is most closely related to the front-end. The emergence of nodejs can be said to give front-end developers a faster way to understand the backend. The following are some of my experiences in learning nodejs from the front-end perspective.
To quickly understand nodejs, you can look at the following aspects: node’s module concept (ECMAScript2015 has supported the front-end and is easy to understand), V8 engine ( Same as browser), asynchronous operation (based on v8 and slightly different from browser processing), event-driven (based on v8 and slightly different from browser), node basic API. [Related tutorial recommendations: nodejs video tutorial, Programming teaching]
module
##nodejs The modules can be roughly divided into three types: core modules, third-party modules, and custom modules. Each module has a different loading priority.//检查fs内存中的缓存是否存在如果不存在则加载fs模块 let fs = require("fs") //检查fs内存中的缓存(无)=》检查是否核心模块=》检查扩展名 let demo = require("./demo")
or
module.exports Externally exposed interface
Asynchronous operations
Asynchronous operations are easy to understand for front-end development. We are full of asynchronous operations, callback functions, and promises in JavaScript. , setTimeout, these are all asynchronous related operations. The most basic DOM rendering is also asynchronous. This is the most closely related area between nodejs and JavaScript. However, please note that there are some differences between these two processing methods. The differences will not be discussed here. Will be updated later. The following is a brief description of the asynchronous characteristics of node:V8 engine
, such as reading and writing files, network requests, system information, etc. On the other hand, because
CPU executes machine code, it is also responsible for interpreting
JavaScript code into a sequence of machine instructions for execution. This part of the work is performed by the
V8 engine Complete
The core of nodejs is V8, v8 is used to compile JavaScript into a language that can be recognized by the machine
Event-driven
Event-driven is actually a commonly used architectural pattern in software architecture. Simply put, it creates (registers) an event and listens to the event, and processes it according to the status of the event. Most of the core APIs in nodejs are built around the idiomatic asynchronous event-driven architecture. In addition, the core module events in node can be used to create custom events.Common API
Server side
In the first few years when nodejs appeared, there was a question about whether to use nodejs In a production environment, most developers are not optimistic about it. However, after practice in recent years, nodejs's single-threaded application in handling high-concurrency scenarios has been well tested. There are currently many nodejs-based services in online products. In addition, nodejs also has many stable server-side frameworks similar to java spring. Here are some commonly used ones
Note: There are many frameworks for different business types. If you are interested, you can learn about them
Tools
When we use vue or react family bucket for development, have you ever thought about why a single line of commands can run the front-end service? Why can one line of commands compile the front-end? Why did our Vue code end up outputting a bunch of js? When we study the source code of these functions, we will find that almost all of these capabilities are developed based on nodejs. The following lists our use of nodejs in daily tools.
I roughly talked about the basics of nodejs from the perspective of the front end. Each point can be taken out individually to explain a lot. Here is just to let everyone know. Have a general understanding of node to facilitate subsequent learning. At present, I have completed many projects using nodejs. After using it more, I can look at some front-end technical developments from a broader perspective.
For more node-related knowledge, please visit: nodejs tutorial!
The above is the detailed content of Basic learning of node: What you need to know about the front-end [Summary]. For more information, please follow other related articles on the PHP Chinese website!