Node features
1. Asynchronous I/O
2. Events, callback functions
3. Single Thread
The transformation of programming ideas:
1. Synchronous programming-------> Asynchronous Programming
2. Single Thread programming
Node Application Scenario
Technology selection is extremely important to select the right technology for different scenarios
1.I/O Intensive
Node takes advantage of the processing power of the event loop instead of starting each thread for each request service
2.cpu Intensive
Module mechanism
COMMONJS specification
Introduction of modules, export, identifiers
Require,module,exports
The process of module loading:
Path parsing, locating files, compiling, etc.
Node module types
1.Node Core Modules
2. Third-party file modules
In a third-party module, the modules are hashed around each other and cannot be directly referenced
In addition to modules, packages and NPM are a mechanism for connecting modules
Specification for CommonJS Packages
Package is to further organize JavaScript code on a module basis
COMMONJS package specification is theory, NPM is the practice
NPM helps third-party modules complete publishing, installation, dependencies, etc.
A good ecosystem is formed between Npm,node and third-party modules.
NPM Common Commands
If you upload your personal package to the NPM repository server, you need to register your account with NPM to create a warehouse
asynchronous I/O
Why does node want to use asynchronous I/O?
1. User Experience
JavaScript and UI rendering in the front-end in the same process, in the case of synchronization, poor response
asynchronous I/O can eliminate front-end UI blocking
2. Resource allocation
Single thread Disadvantage: easy to block I/O, no multi-core CPU resources available
Multithreading disadvantage: Easy to cause deadlock, state synchronization
Node gives the intermediate scenario:
Use single thread, away from multi-threaded deadlock, state synchronization
Leverage asynchronous I/O, away from single-threaded blocking for better CPU utilization
Provides sub-threads like front-end web workers for efficient use of multicore CPUs
Node's asynchronous I/O
Complete the entire asynchronous I/O Link: event loop, observer, request object
Node Asynchronous programming
Nodejs Learn A