OverviewNodejs built-in modules refer to the beauty provided in addition to the default syntax. You don’t need to download them and can directly import them. Just write the name when you import them. Nodejs built-in modules: 1. Path moduleUsed to process file paths.
2. Until moduleTo make up for the lack of js functions, add new API.
3. fs moduleFile system API
4. Events moduleThe events module provides only 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 that 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 sequence, and the event parameters are passed as callback function parameters. 5. http module
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":"I'm really just testing it", "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=IzZDJiMGU0OTMyNTE0ZGFhZDAzZDNhZTAyZDg2ZmQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjkyOTk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 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("Comment completed!"); }); console.log(res.statusCode); }); req.on("error",function(err){ console.log(err.message); }) req.write(postData); req.end(); 6. Jade moduleJade is a high-performance, simple and easy-to-understand template engine. You can use jade to write HTML files. Jade is similar to a language used to quickly write HTML, and the suffix of the written file is .jade. 7. Express FrameworkExpress is a nodejs web open source framework for quickly building web projects. It mainly integrates the creation of web http server, static text management, server URL address request processing, get and post request processing and distribution, session processing and other functions. To use it, open the path where you want to create the web project in cmd. Then enter
You can create a web project named appname. The above is a detailed explanation of the nodejs built-in modules. For more information about nodejs built-in modules, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Example analysis of mysql stored procedure usage
>>: Steps to set up Windows Server 2016 AD server (picture and text)
XML/HTML CodeCopy content to clipboard < div c...
This is the content of React 16. It is not the la...
Effect diagram: Overall effect: Video loading: Ph...
I have been studying and reviewing the developmen...
Preface innodb_data_file_path is used to specify ...
<br />It has been no more than two years sin...
Preface In daily work, we sometimes run slow quer...
1. Edit the PAM configuration file sudo vim /etc/...
SQL implements addition, subtraction, multiplicat...
Before talking about the structural markup of web...
Conventional solution Use FileReader to read the ...
<meta name="viewport" content="...
Table of contents Audio transcoding tools princip...
This article uses an example to describe how to u...
1. Installation Search the mariadb version to be ...