1. URL

There are two sets of methods for URL parsing < null display “”>

  1. Specification (mainstream) : The WHATWG URL API
const URL = require("url").URL; const myUrl = new URL(a); // Parameter A is a string, for example, https://www.baidu.comCopy the code

Myurl.searchparams.get (“ie”)

  1. Node implements url< null value display null>
const URL = require("url"); const myUrl = URL.parse(a); // Parameter A is a string, for example, https://www.baidu.comCopy the code

Road king joining together
const resolve = require("url").resolve; //resolve(a, b)"local/user/sjl"."url"); //local/user/url
Copy the code

Passing in the URL

resolve(https://www.baidu.com, "node");   //https://www.baidu.com/node
Copy the code

2. Qs module (QueryString processing format)

demo

//1. qs.parse
const qs = require("querystring");
const URL = require("url").URL;
const myUrl = new URl(""https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=0&rsv_idx=1&tn=baidu&wd=%E4%BC%B4%E5%A5%B9&rsv_pq=9867bbfc00070dc5&rsv_t=2d8 bV4Pf6LhibJm74DFWLicdMEgP4jKJZ8PQrdss4Wx14X8m%2B2oi9uEnqJw&rqlang=cn&rsv_enter=1&rsv_sug3=14&rsv_sug1=8&rsv_sug7=100&rsv _sug2=0&inputT=8553&rsv_sug4=10518""); 
console.log(qs.parse(myUrl.search.slice(1)));
Copy the code

Effect:

//2. Qs. stringify const qs = require("querystring");
let obj = {
    sjl : 123,
    yl : 456
};
qs.stringify(obj, "@"."$");
Copy the code

Effect:

Second argument: concatenation, default “&” third argument: key-value pair, default “=”


3. Crypto encryption module

const crypto = require('crypto'); //crypto.getHashes ; // The method supported by hash encryptionlet pwd = "sjl520";
const obj = crypto.createHsh("sha256"); // Create a hash encryption with 256 obj.update(pwd); // Encrypt data with an encryption object obj.digest("hex"); // Disgest has obtained a < binary > Buffer object,"hex"Is the hexadecimalCopy the code

Effect: 1. Buffer object


Fs file control module

const fs = require("fs")

  1. Read the file

    Fs.readfile (a, b, c)

    Err: the default value of err is null, indicating that the file is read successfully. Error message is reported when an error occurs ({}). 2.Copy the code
    fs.readFile("./sjl.txt", (err, data) => {
        console.log(err, data);
    }, "utf8"); // Note: After reading the contents of the document, execute the callback only onceCopy the code

    Fs.readfilesync (a, c) : fs.readfilesync (a, c) : fs.readfilesync (a, c)

  2. Write (a, b, c, d)

    C > character set: "utf8" d> callback function: err err: null; error {}Copy the code
    let data = "522";
    fs.writeFile("./sjl.txt", data, "utf8", (err) => {
        console.log(err);
    }, "utf8"); // Note: After reading the contents of the document, execute the callback only onceCopy the code

    2) Sync: fs.writesycn (a, c)

  3. Create folder fs.mkdir()

    fs.mkdir("./sjl", err=>{ console.log(err); }); Note: you can only create a single folder, create existing folder will report an errorCopy the code
  4. Read fs.readdir()

    fs.readdir("./sjl", (err, data)=>{//data: file data, all folders and files})Copy the code
  5. Const stat = fs.statsync (” static “)

    1. Stat.isdirectory ();
    2. Stat. IsFlie (); .

Returns a Boolean value