basic usage of 1.normalize functions
The normalize function converts a path that does not conform to a specification to a standard path, which is resolved in a path. , you can also remove the extra slash.
The following example:
- var path = require(' path ');
- var data = path. Normalize('/path///normalize/hi/.. ') );
- Console. Log(data);
Operation Result:
- '/path/normalize/'
basic usage of 2.join functions
The Join function joins the multiple paths that are passed into a standard path and formats them, returning the canonical path, avoiding the tedious use of manually stitching the path strings. The following example:
- var path = require(' path ');
- var data = path. Join('///you ', '/are ', '//beautiful ');
- Console. Log(data);
Operation Result:
- '/you/are/beautiful '
basic usage of 3.dirname functions
The DirName function is used to return the directory name in the path. The following example:
- var path = require(' path ');
- var data = path. DirName('/foo/strong/cool/nice ');
- Console. Log(data);
Operation Result:
- '/foo/strong/cool '
basic usage of 4.basename functions
The basename function returns the last part of the path and can be conditionally excluded. The following example:
Example 1:path.basename (' path string ');
Example 2:path.basename (' Path string ', ' [ext] ') < exclude [ext] suffix string >;
- var path = require(' path ');
- var data1 = path. basename('/foo/strong/basename/index.html ');
- var data2 = path. basename('/foo/strong/basename/index.html ','. html ');
- Console. Log(data1 + ' "and" ' + data2);
Operation Result:
- ' index.html ' and ' index '
basic usage of 5.### extname function
The Extname function returns the extension of the file in the path (in the last '. ') Start, return '. ' and '. ' All subsequent strings, such as no '. ', return an empty string). The following example:
- var path = require(' path ');
- var data = path. Extname(' index.html ');
- Console. Log(data);
Operation Result:
- '. html '
Node. JS (quad) path optimization (path optimization)