1. The path module
-
How do I know my current location and the location of the target folder as a basis for operating on local files
-
Path is an object with many properties and methods inside
-
Posix: Portable operating system interface, specification that defines some apis
-
Join method: join path
Join (__dirname,” join path “)
__dirname: directory name of the current file (absolute path), __filename: directory name of the current file + filename (absolute path)
-
Resolve method: Used to convert a relative path to an absolute path
-
Relative method: The method takes two parameters, both of which should be absolute paths. This method returns the relative path of the second path relative to the first path.
-
Parse method: Parses a directory and returns information about each part of the path
Return parameters:
1. Root: The root directory of a path, usually a drive (/ in Linux).
2. Dir: is the absolute path of the file (in dirname mode, this is the parent directory of the file directory).
3. Base: basic information about the file (in dirname mode, this is the relative path of the file directory to the parent directory)
4. Ext: extension of file (dirname mode, no suffix, null value)
5. Name: file name (in dirName mode, this is the folder name)
2. The url module
-
The URL module is used to generate and parse urls. This module must be loaded before use.
-
The URL module provides two sets of apis to handle urls: a legacy API from the older version and a new API that implements the WHATWG standard.
The old API is part of url.parse, and the new API is part of the URL
-
It is recommended to use the new version and import modules using deconstructed assignments
-
A URL is a constructor that can be used in two ways
① Pass in a complete absolute address
let {URL} = require("url") let nowUrl = ("https://juejin.cn/user/1442193016097928") Copy the code
② The first parameter is passed into the relative path, and the second parameter is passed into the absolute path. The two parameters are spliced for analysis
let nowUrl2 = new URL("/ 1442193016097928"."https://juejin.cn/user") console.log(nowUrl2); Copy the code
Parameter analysis:
1. Hash: Gets and sets the fragment of the URL. Invalid URL characters contained in the value assigned to the hash attribute are percent-encoded
2. Host: Gets and sets the host part of the URL. (Domain name plus port)
3. Url.hostname: gets and sets the hostname part of the url. The difference between url.host and url.hostname is that url.hostname does not contain a port
Href: Gets and sets the serialized URL. Getting the value of the href attribute is equivalent to calling url.tostring (). Setting the value of this property to a new value is equivalent to creating a new URL object using new URL(value). Each property of the URL object will be modified. If the value set to the href attribute is an invalid URL, TypeError will be raised.
5. Origin: contains the host of the protocol, and gets the origin of the read-only serialized URL.
6. Port: Port Gets and sets the port portion of the URL. The port value can be a number or a string of numbers ranging from 0 to 65535. The port can be an empty string, in which case the port is automatically selected according to the protocol
7. Protocol: Sets the connection protocol. Invalid protocol values are ignored. Like HTTP or HTTPS
8. Search: Gets and sets the serialized query portion of the URL.
SearchParams: Gets the URLSearchParams object that represents the URL query parameters. This property is read-only. Replace the entire query parameter of the URL with the url.search setting
3. querystring
The module
-
The QueryString module is mainly used to parse query strings
-
The querystring.parse() method is used to parse a querystring into a JavaScript object.
-
The parse method can accept a total of four arguments.
① STR: query string to be parsed
② sep: separator between multiple key-value pairs. The default value is &
③ eq: separator between key name and key value. The default value is =
(4) the options: DecodeURIComponent is a function to restore the encoded string. The default is querystring.unescape(). By default, percent-encoded characters in the querystring are assumed to be utf-8 encoded. If other character encodings are used, other values need to be specified; The maxKeys attribute specifies the maximum number of attributes to parse. The default is 1000, and a value of 0 indicates an unlimited maximum number of attributes.
4.os
The module
-
The OS module provides methods specific to the operating system
-
The os.EOL property is a constant that returns the newline character of the current operating system (\r\n on Windows, \n on other systems). Remember, this newline character is invisible, so we see the effect
-
Os.arch () returns the architecture of the current computer
Possible values now are: ‘ARM’, ‘ARM64’, ‘ia32’, ‘MIPS’, ‘MIpsel’, ‘PPC’, ‘PPC64’, ‘S390’, ‘S390x’, ‘x32’, ‘x64’
-
The s.networkInterfaces() method returns an object containing only the network interfaces that are assigned network addresses.
The object assigned a network address contains the following properties:
1. Address Specifies the assigned IPv4 or IPv6 address.
2.net Mask IPv4 or IPv6 subnet mask.
3. Family IPv4 or IPv6.
4. MAC Indicates the MAC address of the network interface.
5. Internal The value is true if the network interface is loopback or similar remote unavailable interfaces; otherwise, it is false.
6. Scopeid IPv6 digital domain identifier (available only when family is IPv6).
Cidr IPv4 or IPv6 address assigned in CIDR notation with a route prefix. If the netmask parameter is not available, this property is null.
-
Os.platform (): Returns a string specifying the operating system platform on which Node.js was compiled
Release (): Returns an operating system version number
Cpus (): returns information about a logical CPU core