search
HomeWeb Front-endJS TutorialBasic learning of node: What you need to know about the front-end [Summary]

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!

Basic learning of node: What you need to know about the front-end [Summary]

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.

Basic features

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.

    Core module: nodejs built-in module, which can be understood as the basic API of nodejs, such as our commonly used path os fs and so on. These modules are also the basis for our nodejs to interact with the server.
  • Third-party module: npm package installed by the nodejs package management tool platform.
  • Custom module: This usually represents our own defined file module.

Module loading and compilation

    File parsing path: Check if cache exists=》Check if it is a core module=》Check extension=》 Parsing execution (according to different suffix names)
  • //检查fs内存中的缓存是否存在如果不存在则加载fs模块
    let fs = require("fs")
    //检查fs内存中的缓存(无)=》检查是否核心模块=》检查扩展名
    let demo = require("./demo")
    Cache priority principle: From the file parsing path, we can see that nodejs will first check whether the cache in the memory exists, and if it exists, load the cache.
  • Module compilation: This article will not explain this process. The next chapter will explain this process in detail.

Standards

The basic concept of JavaScript module development is as follows: "script" introduction => scope function => self-executing function => Commonjs (AMD ). Modules in nodejs mainly adopt commonjs specifications, as shown below.

    Each file is a module and has its own scope.
  • The variables, functions, and classes defined in each file are private and invisible to other files
  • Each module can be accessed through
  • exports or module.exports Externally exposed interface
  • Each module loads another module through
  • require
We commonly use require exports in nodejs module.exports It is based on Commonjs.

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:

    Asynchronous is realized through Event Loop, which includes the concepts of macro tasks and micro tasks
  • Node and JavaScript have some differences in asynchronous processing Difference
A picture of the event loop found on the Internet:

Basic learning of node: What you need to know about the front-end [Summary]

V8 engine

    V8 is the name of the JavaScript engine that drives Google Chrome. This is something that takes our JavaScript and executes it while browsing with Chrome.
  • In Nodejs, v8 is used. It provides a variety of callable
  • API, 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 machineBasic learning of node: What you need to know about the front-end [Summary]

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

  • fs: Commonly used for file viewing, editing, creation and other operations
  • http: The key to the network Module
  • socket: socket network communication
  • events: event module

Application scenario

  • Background service
  • Script processing

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

  • Koa: Onion model development model
  • Express: Routing as the core Server-side nodejs framework
  • Fastify: A framework that takes up very little resources and is extremely fast. Currently, it is the fastest framework.

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.

  • Local service: The local service plug-ins enabled by webpack are all implemented based on the http module of nodejs
  • Compilation and packaging: vue's .vue file, react's jsx or commonly used .ts files How did it finally become a js file? Everyone thinks it was webpack. In fact, the entire webpack is based on nodejs. The ability to compile files is closely related to the fs module of nodejs.

Summary

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!

Statement
This article is reproduced at:掘金社区. If there is any infringement, please contact admin@php.cn delete
Python vs. JavaScript: A Comparative Analysis for DevelopersPython vs. JavaScript: A Comparative Analysis for DevelopersMay 09, 2025 am 12:22 AM

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Python vs. JavaScript: Choosing the Right Tool for the JobPython vs. JavaScript: Choosing the Right Tool for the JobMay 08, 2025 am 12:10 AM

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript: Understanding the Strengths of EachPython and JavaScript: Understanding the Strengths of EachMay 06, 2025 am 12:15 AM

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScript's Core: Is It Built on C or C  ?JavaScript's Core: Is It Built on C or C ?May 05, 2025 am 12:07 AM

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript Applications: From Front-End to Back-EndJavaScript Applications: From Front-End to Back-EndMay 04, 2025 am 12:12 AM

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Python vs. JavaScript: Which Language Should You Learn?Python vs. JavaScript: Which Language Should You Learn?May 03, 2025 am 12:10 AM

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

JavaScript Frameworks: Powering Modern Web DevelopmentJavaScript Frameworks: Powering Modern Web DevelopmentMay 02, 2025 am 12:04 AM

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

The Relationship Between JavaScript, C  , and BrowsersThe Relationship Between JavaScript, C , and BrowsersMay 01, 2025 am 12:06 AM

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function