Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the core modules of nodejs

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what are the core modules of nodejs". In daily operation, I believe many people have doubts about the core modules of nodejs. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the questions of "what are the core modules of nodejs?" Next, please follow the editor to study!

Nodejs core module: 1, HTTP module, used to deal with the client's network request; 2, URL module, used to deal with the client request from the URL;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 12.19.0, Dell G3 computer.

HTTP module of Node core module

Function:

Handle the client's network request

Code steps:

1. Import HTTP core module

two。 Listen for client requests

3. Processing requests from clients

4. Turn on the server

URL module of Node core module

Function:

Handle the URL requested by the client

Code steps:

1. Import URL core module

two。 Import HTTP core module

3. Listen for client requests

The URL requested by the client is handled in the middle.

4. Processing requests from clients

5. Turn on the server

Query Strings module of NodeJS core module

Function:

Handle the parameters passed by the client through the `get/ post` request

Use keys:

1. The core module 'querystring'' needs to be imported

2. Querystring is usually used in conjunction with the core module of url when requesting.

3. In the end, all the `get / post` requests need to call the querystring.parse method to convert the key-value pair passed by the request into a js object, which is convenient for operation.

Note:

The request method of get/post is different. When the client passes it, the parameters are placed in the

Is different, so the server side handles it differently.

File System module of NodeJS core module

Premise:

In the future, all static resources (html,css,js, pictures, etc.) are placed on the server. If the browser needs these html,css,js, pictures and other resources, it needs to be read into the content of node.exe and then returned to the browser.

Function:

When you manipulate the file on the server, you may need to save the picture uploaded by the browser to the server, or you may need to read the resources of the server and return it to the browser.

Code steps:

1. Import fs core module

two。 Use the appropriate methods to write files, read files, etc.

Path module of NodeJS core module

Action

Manipulate the path of the file to serve the file operation

Global module of NodeJS core module

Function:

Globally shared, without the need to import modules to use the

Commonly used attributes:

_ _ dirname: the path to the folder where the file is located

_ _ filename: the path where the file is located

Require (): import the required modules

Module: used when customizing modules

Exports: used when customizing modules

Events module of NodeJS core module

The events module provides only one object: events.EventEmitter.

The core of EventEmitter is the encapsulation of event triggers and event listeners. ]

Each event in EventEmitter consists of an event name and several parameters, and the event name is a string that usually expresses a certain semantics. For each event, EventEmitter supports several event listeners. When an event is triggered, the event listeners registered to the event are called in turn, and the event parameters are passed as callback function parameters.

At this point, the study of "what are the core modules of nodejs" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report