路徑模塊
-
導入模塊
let path=require('path')
-
獲取路徑信息擴展名
let info=path.extname('https://timgsa.baidu.86.jpg') console.log(info) // .jpg
-
把一個路徑或者路徑片段解析爲一個絕對路徑
let infoPath=path.resolve('../learn04') console.log(infoPath) // E:\webstudy\node\learn04
-
獲取當前所在目錄的完整路徑
// 當前文件就是learn05文件夾下 console.log(__dirname) // E:\webstudy\node\learn05
-
路徑拼接
let infoPath2=path.join(__dirname,'/hello.txt') console.log(infoPath2) // E:\webstudy\node\learn05\hello.txt
-
獲取當前的執行文件
console.log(__filename) // E:\webstudy\node\learn05\index.js
-
解析路徑
let pathObj=path.parse(__filename) console.log(pathObj) /* { root: 'E:\\', dir: 'E:\\webstudy\\node\\learn05', base: 'index.js', ext: '.js', name: 'index' } */
系統模塊
-
導入系統模塊
let os=require('os')
-
獲取
cpu
信息console.log(os.cpus())
-
獲取內存信息
console.log(os.totalmem())
-
查看系統的架構
console.log(os.arch()) // x64
-
閒置的內存量
console.log(os.freemem())
-
查看系統平臺
console.log(os.platform())