var path = require (' path ');//When multiple consecutive slashes are found, they are replaced by one; when the end of the path contains a slash, it is preserved;//The Windows system uses a backslash. var p = path.normalize (' foo/bar//baz/asdf/quux/. '); var p2 = path.normalize (' foo/bar//baz/asdf/quux/. /'); Console.log (' P ', p,p2);//All paths in the combined parameter, returning the normalized path. var p3 = path.join (' a/b/c ', "d/c/v"); Console.log (' P3 ', p3);//returns the absolute path of the file var P4 = path.resolve (' test.js '); var P5 = Path.resolve ('/path/test.js '); Console.log (' P4 ', p4); Console.log (' P5 ', p5);//var AB = Path.isabsolute (' test.js ');// Console.log (' ab ', AB);//returns the relative path from the from to to to var res = path.relative ('/data/orandea/test/aaa ', '/data/orandea/impl/bbb '); Console.log (' res ', res);//path.resolve (from, path.relative (from)) = = Path.resolve (to)//File folder name var Dir1 = Path.dirname ('.. /test.js ') var dir2 = Path.dirname ('./test.js '); var dir3 = Path.dirname (' test.js '); var dir4 = Path.dirname ('/foo/bar/ Baz/asdf/quux ');//dir1. Dir2.//dir3//dir4/foo/bar/baz/asdfconsole.log (' Dir1 ', dir1); Console.log (' Dir2 ', Dir2); Console.log (' Dir3 ', dir3 ); Console.log (' Dir4 ', DIR4);//Returns the base name of the file after the second parameter is the suffix name if present returns the name after removing the suffix var base1 = path.basename ('/foo/bar/baz/asdf/quux.html ', '. html '); var base1 = Path.basename ('/foo/bar/baz/asdf/quux.html ', '. htm '), var base2 = path.basename ('/foo/bar/baz/asdf/quux.html ', ' html var base3 = path.basename ('/foo/bar/baz/asdf/quux.html ');//Base1 quux//base2 quux.//base3 quux.htmlconsole.log (' B Ase1 ', base1); Console.log (' Base2 ', base2); Console.log (' Base3 ', base3);//return suffix name, no null var en1 = path.extname (' test.js ') var en2 = path.extname (' Test '), Console.log (' En1 ', EN1), Console.log (' En2 ', en2),//en1. js//en2//path.sep path delimiter var sp = ' Foo/bar/baz '. Split (PATH.SEP);//sp [' foo ', ' Bar ', ' Baz ']console.log (' SP ', SP);//Path.delimiter delimiter between multiple paths var del = Pro Cess.env.PATH split (Path.delimiter); Console.log (' del ', Del);//de ['/usr/local/bin ',//'/usr/bin ',//'/bin ',//' /usr/sbin ',//'/sbin ',//'/usr/local/bin ',//'/usr/local/git/bin ']
Run directly
Path module in Nodejs