nodejs built-in modules: 1. path module, used to process file paths, the introduction syntax is "require('path')"; 2. until module, used to make up for the lack of js functions and add new APIs; 3 , fs module, the API of the file operating system; 4. events module, which provides an "events.EventEmitter" object; 5. jade module, which can write html files through jade.
The operating environment of this article: Windows 10 system, nodejs version 12.19.0, Dell G3 computer.
What are the built-in modules of nodejs?
The built-in modules of nodejs refer to the beauty provided in addition to the syntax provided by default. There is no need to download it. It can be introduced directly. Just write the name.
Nodejs built-in modules:
1. Path module
is used to process file paths.
path.normalize(path parsing, get the canonical path);
path.join(path merge);
path.resolve(get the absolute path);
path.relative(get relative path).
......
2. Until module
Make up for the lack of js functions and add new APIs.
util.format(formatted output string);
util.isArray(check whether it is an array);
util.RegExp(whether it is regular);
util.isDate (is it date type);
util.inherits(child, parent) implements inheritance;
3. fs module
File operating system API
fs.readFile(filename,[options],callback); Read the file.
fs.writeFile(filename,data,[options],callback);Write file.
fs.appendFile(filename,data,[options],callback);Write the file in append mode.
fs.open(filename,flags,[mode],callback); Open the file.
filename: file name, required.
data: written data or buffer stream.
flags: operation identification, opening method, r w.
[options]: Specify permissions, read, write, execute. Whether it can be continued.
callback: callback function after reading the file. function(err, data);
fs.mkdir(path,[mode],callback);Create directory.
fs.readdir(path,callback);Read the directory.
fs.exists(path,callback); Check whether the file and directory exist.
fs.utimes(path,atime,mtime,callback);Modify the access time and modification time of the file.
fs.rename(oldfilename,newfilename,callback);Rename the file name or directory.
fs.rmdir(path,callback);Delete empty directories.
path: The full path and directory name of the created directory.
[mode]: Directory permissions, default 0777 (readable, writable and executable).
atime: New access time.
ctime: New modification time.
oldfilename, newfilename Old name and new name.
callback: callback function after creating the directory.
4. events module
The events module only provides one object: events.EventEmitter.
[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.
5. http module
http.createServer(function(){});Create a server.
http.get('path',callback);Send a get request.
http.request(options,callback);Send request.
options: options is an object similar to an associative array, representing the parameters of the request. As a callback function, callback needs to pass a parameter.
Options commonly used parameters include host, port (default is 80), method (default is GET), path (the requested path relative to the root, the default is "/".
get :
var http=require("http"); var options={ hostname:"cn.bing.com", port:80 } var req=http.request(options,function(res){ res.setEncoding("utf-8"); res.on("data",function(chunk){ console.log(chunk.toString()) }); console.log(res.statusCode); }); req.on("error",function(err){ console.log(err.message); }); req.end();
post
var http=require("http"); var querystring=require("querystring"); var postData=querystring.stringify({ "content":"我真的只是测试一下", "mid":8837 }); var options={ hostname:"www.imooc.com", port:80, path:"/course/document", method:"POST", headers:{ "Accept":"application/json, text/JavaScript, */*; q=0.01", "Accept-Encoding":"gzip, deflate", "Accept-Language":"zh-CN,zh;q=0.8", "Connection":"keep-alive", "Content-Length":postData.length, "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8", "Cookie":"imooc_uuid=6cc9e8d5-424a-4861-9f7d-9cbcfbe4c6ae; imooc_isnew_ct=1460873157; loginstate=1; apsid=IzZDJiMGU0OTMyNTE0ZGFhZDAzZDNhZTAyZDg2ZmQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjkyOTk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAGNmNmFhMmVhMTYwNzRmMjczNjdmZWUyNDg1ZTZkMGM1BwhXVwcIV1c%3DMD; phpSESSID=thh4bfrl1t7qre9tr56m32tbv0; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1467635471,1467653719,1467654690,1467654957; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1467655022; imooc_isnew=2; cvde=577a9e57ce250-34", "Host":"www.imooc.com", "Origin":"http://www.imooc.com", "Referer":"http://www.imooc.com/video/8837", "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/53.0.2763.0 Safari/537.36", "X-Requested-With":"XMLHttpRequest", } } var req=http.request(options,function(res){ res.on("data",function(chunk){ console.log(chunk); }); res.on("end",function(){ console.log("评论完毕!"); }); console.log(res.statusCode); }); req.on("error",function(err){ console.log(err.message); }) req.write(postData); req.end();
6. jade module
jade is a high-performance, concise and easy-to-understand template engine. It can Write html files through jade.
jade is similar to a language for quickly writing html, and the suffix of the written file is .jade.
7. Express framework
Express is a nodejs web open source framework, used to quickly build web projects. It mainly integrates the creation of web http servers, static text management, server URL address request processing, get and post request processing and distribution , session processing and other functions.
Usage method, open the path of the web project you want to create in cmd. Then enter
Express appname
to create a file named appname's web project.
Recommended learning: "nodejs video tutorial"
The above is the detailed content of What are the built-in modules of nodejs?. For more information, please follow other related articles on the PHP Chinese website!

React’s popularity includes its performance optimization, component reuse and a rich ecosystem. 1. Performance optimization achieves efficient updates through virtual DOM and diffing mechanisms. 2. Component Reuse Reduces duplicate code by reusable components. 3. Rich ecosystem and one-way data flow enhance the development experience.

React is the tool of choice for building dynamic and interactive user interfaces. 1) Componentization and JSX make UI splitting and reusing simple. 2) State management is implemented through the useState hook to trigger UI updates. 3) The event processing mechanism responds to user interaction and improves user experience.

React is a front-end framework for building user interfaces; a back-end framework is used to build server-side applications. React provides componentized and efficient UI updates, and the backend framework provides a complete backend service solution. When choosing a technology stack, project requirements, team skills, and scalability should be considered.

The relationship between HTML and React is the core of front-end development, and they jointly build the user interface of modern web applications. 1) HTML defines the content structure and semantics, and React builds a dynamic interface through componentization. 2) React components use JSX syntax to embed HTML to achieve intelligent rendering. 3) Component life cycle manages HTML rendering and updates dynamically according to state and attributes. 4) Use components to optimize HTML structure and improve maintainability. 5) Performance optimization includes avoiding unnecessary rendering, using key attributes, and keeping the component single responsibility.

React is the preferred tool for building interactive front-end experiences. 1) React simplifies UI development through componentization and virtual DOM. 2) Components are divided into function components and class components. Function components are simpler and class components provide more life cycle methods. 3) The working principle of React relies on virtual DOM and reconciliation algorithm to improve performance. 4) State management uses useState or this.state, and life cycle methods such as componentDidMount are used for specific logic. 5) Basic usage includes creating components and managing state, and advanced usage involves custom hooks and performance optimization. 6) Common errors include improper status updates and performance issues, debugging skills include using ReactDevTools and Excellent

React is a JavaScript library for building user interfaces, with its core components and state management. 1) Simplify UI development through componentization and state management. 2) The working principle includes reconciliation and rendering, and optimization can be implemented through React.memo and useMemo. 3) The basic usage is to create and render components, and the advanced usage includes using Hooks and ContextAPI. 4) Common errors such as improper status update, you can use ReactDevTools to debug. 5) Performance optimization includes using React.memo, virtualization lists and CodeSplitting, and keeping code readable and maintainable is best practice.

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.

React components can be defined by functions or classes, encapsulating UI logic and accepting input data through props. 1) Define components: Use functions or classes to return React elements. 2) Rendering component: React calls render method or executes function component. 3) Multiplexing components: pass data through props to build a complex UI. The lifecycle approach of components allows logic to be executed at different stages, improving development efficiency and code maintainability.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment