# 1 # path module

path module for parsing the file path

1 var path=require('path')
2 var pathTest='./toggleNum.html'
3 var resultPath=path.resolve(pathTest)
// path.resolve (): the relative path into an absolute path
5 console.log(path.dirname(resultPath))
// Get directory 
// D: \ project108 \ self \ test
6 console.log(path.basename(resultPath))
// path.basename (): Gets the file name extension. 
// toggleNum.html
7 console.log(path.extname(resultPath))
// get the extension (Extension name) 
// .html
8 console.log(path.parse(resultPath))
// convert a path to a target js 
@ {the root: 'D: \\', 
 the dir: 'D: project108 \\ \\ \\ Self Test', 
  Base: 'toggleNum.html', 
  EXT: '. HTML ', 
  name:' toggleNum '}
 
 
9 console.log(__dirname)
// __dirname: js always returns the absolute path to the folder where the file is executed 
// D: \ project108 \ Self \ the Test

10 console.log(__filename)

// always returns js executed the absolute path 
// D: \ project108 \ Self \ the Test \ path.js

. 11  path.format (): to convert into a path of objects js

12 path.join (): spliced ​​into a plurality of paths path

 

Guess you like

Origin www.cnblogs.com/alley715/p/11667998.html