The path module provides the function of operating paths. The more commonly used APIs are:
API |
illustrate |
path.resolve |
Absolute path of splicing specification [commonly used] |
path.sep |
Get the path separator of the operating system |
path.parse |
Parse the path and return the object |
path.basename |
Get the base name of a path |
path.dirname |
Get the directory name of the path |
path.extname |
Get the extension of the path |
const fs = require('fs')
const path = require('path')
console.log(__dirname + '/index.html');
console.log(path.resolve(__dirname , './index.html'));
console.log(path.resolve(__dirname , 'index.html'));
console.log(path.sep);
console.log(__filename);
let str = 'E:\\3.前端项目\\NodeJs学习\\path.js'
console.log(path.parse(str));
console.log(path.basename(str));
console.log(path.dirname(str));
console.log(path.extname(str));