In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what native modules does node have". In daily operation, I believe many people have doubts about what native modules node has. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what native modules does node have?" Next, please follow the editor to study!
Node native modules are: 1, path module, used to deal with file path; 2, until module; 3, fs module, file operating system API;4, events module; 5, http module; 6, jade module, a high-performance, simple and easy to understand template engine; 7, Express framework.
This tutorial operating environment: windows7 system, nodejs version 12.19.0, DELL G3 computer.
Nodejs native (built-in) module refers to the introduction of write-only names without downloading, in addition to the syntax provided by default.
Nodejs native module:
1. Path module:
Used to process file paths.
Path.normalize (path parsing to get canonical paths); path.join (path merging); path.resolve (getting absolute paths); path.relative (getting relative paths). .
2. Until module:
To make up for the lack of js function, add API.
Util.format (formatted output string); util.isArray (check whether it is an array); util.RegExp (regular); util.isDate (date type); util.inherits (child,parent) implementation inheritance
3. Fs module:
API of the file operating system
Fs.readFile (filename, [options], callback); read the file. Fs.writeFile (filename,data, [options], callback); write the file. Fs.appendFile (filename,data, [options], callback); write the file as an append. Fs.open (filename,flags, [mode], callback); open the file. Filename: file name, required. Data: written data or buffer stream. Flags: operation identification, opening mode, r w. [options]: specify permissions, read, write, and execute. Whether it can be renewed. Callback: the callback function after reading the file. Function (err,data); fs.mkdir (path, [mode], callback); create a directory. Fs.readdir (path,callback); read the directory. Fs.exists (path,callback); check to see if files and directories exist. Fs.utimes (path,atime,mtime,callback); modify the access time and modification time of the file. Fs.rename (oldfilename,newfilename,callback); rename a file name or directory. Fs.rmdir (path,callback); delete the empty directory. Path: the full path and directory name of the directory to be created. [mode]: directory permission. Default is 0777 (readable, writable and executable). Atime: new visit time. Ctime: new modification time. Oldfilename, newfilename old name and new name. Callback: the callback function after the directory is created.
4. Events 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.
5. Http module
Http.createServer (function () {}); create a server. Http.get ('path', callback); send a get request. Http.request (options,callback); send the request. Options:options is an object similar to an associative array that represents the parameters of the request. Callback, as a callback function, needs to pass a parameter. The commonly used parameters for options are host, port (default is 80), method (default is GET), and path (the path of the request relative to the root, and 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": "I'm really just testing", "mid": 8837}); var options= {hostname: "www.imooc.com", port:80, path: "/ course/document", method: "POST", headers: {"Accept": "application/json, text/JavaScript, * / *" Qroom0.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-9f7dMuth9cbcfbe4c6ae; imooc_isnew_ct=1460873157; loginstate=1 " Apsid=IzZDJiMGU0OTMyNTE0ZGFhZDAzZDNhZTAyZDg2ZmQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjkyOTk0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAGNmNmFhMmVhMTYwNzRmMjczNjdmZWUyNDg1ZTZkMGM1BwhXVwcIV1c%3DMD; phpSESSID=thh5bfrl1t7qre9tr56m32tbv0; 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 (" finished comment! ") ); 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, simple and easy-to-understand template engine. Html files can be written through jade.
Jade is similar to a language for writing html quickly, with a file suffix of .jade.
7. Express framework
Express is an nodejs web open source framework for quickly building web projects. It mainly integrates the functions of web's http server creation, static text management, server URL address request processing, get and post request processing and distribution, session processing and so on.
Using the method, open the path where you want to create the web project in cmd. Then enter
Express appname
You can create a web project called appname.
At this point, the study of "what are the native modules of node" 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.