The core modules of nodejs: 1. HTTP module, used to process network requests from clients; 2. URL module, used to process URLs requested by clients; 3. Query Strings module; 4. File System module ; 5. Path module; 6. Global module and so on.
The operating environment of this tutorial: windows7 system, nodejs version 12.19.0, Dell G3 computer.
Function:
Process the client’s network request
Code Steps:
1. Import the HTTP core module
2. Listen to the client’s request
3. Process the client’s request
4. Start the server
Function:
Process the URL requested by the client
Code steps:
1. Import the URL core module
2. Import the HTTP core module
3. Monitor the client’s request
Process the URL requested by the client
4. Process the client's request
5. Start the server
##Function:
Processing parameters passed by the client through `get/post` requestKey points to use:
1. Need to import the core module 'querystring' 2. When making a `get` request, querystring is generally used in conjunction with the url core module
3. `get/post` requests ultimately need to call the querystring.parse method to convert the key-value pair string passed by the request. into a js object for easy operation
Note:
The request method of get/post is different. When the client passes it over, the parameters are placed in The places are different, so the server-side processing methods are also different
Function:
To operate files on the server side, you may need to save the pictures uploaded by the browser to the server, or It may be necessary to read the server's resources and return them to the browserCode steps: 1. Import the fs core module 2. Use the corresponding method to write files, read Fetch files and other operations
Function
The path of the operation file is File operation serviceFunction:
Globally shared, no need to import the module You can useCommonly used attributes:
__dirname: The path to the folder where the file is located __filename: The path to the file
require(): Import requirements Module
module: used when customizing the module
exports: used when customizing the module
[The core of EventEmitter is the encapsulation of event triggering and event listener functions. 】
Each event of EventEmitter consists of an event name and several parameters. The event name is a string, which usually expresses certain semantics. For each event, EventEmitter supports several event listeners. When an event is triggered, the event listeners registered to this event are called in turn, and the event parameters are passed as callback function parameters.
[Recommended learning: "
nodejs tutorialThe above is the detailed content of What are the core modules of nodejs?. For more information, please follow other related articles on the PHP Chinese website!