【Node.js】—Summary of basic knowledge points

【Node.js】—Summary of basic knowledge

1. Commonly used operations on the command line

Insert image description here

2. Points to note about Node.js

BOM and DOM operations cannot be used in Node.js

Insert image description here
Insert image description here

Summarize

Insert image description here

3. Buffer

  • buffer is an array-like object used to represent a fixed-length sequence of bytes
  • The essence of buffer is a memory space specially used to process binary data
    Insert image description here
    . Characteristics:
  • The buffer size is fixed and cannot be adjusted
  • The buffer performance is good and can directly operate on the computer memory.
  • The size of each element is 1 byte

Insert image description here

4. Creation of buffer

Insert image description here

//alloc
let buf=Buffer.alloc(10);
console.log(buf);

//allocUnsafe

let buf_2=Buffer.allocUnsafe(10);
console.log(buf_2);

//from
let buf_3=Buffer.from('hello');
console.log(buf_3);

Insert image description here
Insert image description here

5. Basic components of computer

Insert image description here

6. Basic process of program operation

Insert image description here

  • Programs are generally saved on the hard disk. The process of software installation is the process of writing the program to the hard disk.
  • When the program is running, it is loaded into the memory, and then the CPU reads and executes the program.

7. Processes and Threads

  • Process: simply understood as an ongoing program
  • Thread: A thread is an execution stream executed in a process. A thread belongs to a certain process.
  • Relationship: Process is the smallest unit for system allocation of resources, and thread is the smallest unit for system scheduling.
  • A process contains threads , and each process has at least one thread, the main thread. Threads within a process can share resources.

8. fs (file system)

Insert image description here

const fs=require('fs');

fs.writeFile('./座右铭.txt','好好学习',err=>{
    
    
    if(err){
    
    
        console.log('写入失败');
        return;
    }
    console.log('写入成功');
})

Insert image description here
Insert image description here

Scenarios for writing files

File writing is a very common operation on computers. File writing is used in the following scenarios (when data needs to be persisted, file writing should be thought of)

  • download file
  • Installation files
  • Keep program logs, such as Git
  • Editor save file
  • video recording

9. HTTP protocol

Insert image description here

10. Request message structure

Insert image description here
Insert image description here
Insert image description here
Common request methods
Insert image description here

Insert image description here
Insert image description here
Insert image description here

11. Response message structure

Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here

12. Introduction to IP

Insert image description here

Classification of IP

Insert image description here

13. Port

The port is the digital identification of the application, and its main function is to realize communication between different host applications.

14. Create HTTP server

Insert image description here

Precautions

Insert image description here

15. Node.js modularization

Insert image description here
Insert image description here

16. Import file module

Insert image description here

Basic process of importing modules

Insert image description here
Insert image description here

17. Package management tools

Insert image description here
Insert image description here
Insert image description here

Basic usage of npm

Insert image description here
Insert image description here
Insert image description here
Insert image description here

18. Development environment and production environment

Insert image description here

Global installation

Global installation: automatically start node applications

Insert image description here
Insert image description here
Insert image description here

19. npm configuration alias

Insert image description here
Insert image description here
Additional instructions:

  • npm start is a common command in projects, generally used to start projects
  • npm run has the feature of automatically searching in the upper directory, the same as the require function.
  • For unfamiliar projects, we can refer to some operations of the project by viewing the scripts attribute.

Twenty, cnpm

Insert image description here

Twenty-one, yarn

Insert image description here

Choice of npm and yarn

Insert image description here

22. Extended content

Insert image description here

nvm switches node version for installation

Insert image description here

Guess you like

Origin blog.csdn.net/m0_46374969/article/details/132706909