【Node.js】—Summary of basic knowledge
1. Commonly used operations on the command line
2. Points to note about Node.js
BOM and DOM operations cannot be used in Node.js
Summarize
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
. 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
4. Creation of buffer
//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);
5. Basic components of computer
6. Basic process of program operation
- 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)
const fs=require('fs');
fs.writeFile('./座右铭.txt','好好学习',err=>{
if(err){
console.log('写入失败');
return;
}
console.log('写入成功');
})
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
10. Request message structure
Common request methods
11. Response message structure
12. Introduction to IP
Classification of IP
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
Precautions
15. Node.js modularization
16. Import file module
Basic process of importing modules
17. Package management tools
Basic usage of npm
18. Development environment and production environment
Global installation
Global installation: automatically start node applications
19. npm configuration alias
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.