Node.js中path模塊操作路徑的基本使用
path模塊提供了操作路徑的功能,以下為常用的API。
path.resolve():拼接規(guī)范的絕對(duì)路徑
const path = require("path"); // 目錄的絕對(duì)路徑 // __dirname: D:\node\path const pathStr = path.resolve(__dirname, "index.html"); // 拼接前后路徑為絕對(duì)路徑 // D:\node\path\index.html console.log(pathStr);
path.parse():解析路徑并返回對(duì)象
const path = require("path"); // 返回該文件的信息對(duì)象 console.log(path.parse("文件路徑"))
path.basename():獲取文件的名稱
const path = require("path"); // index.html console.log(path.basename("文件路徑"))
path.dirname():獲取路徑的目錄名
const path = require("path"); // D:\node\path console.log(path.dirname("文件路徑"))
path.extname():獲取路徑的擴(kuò)展名
const path = require("path"); // .html console.log(path.extname("文件路徑"))
到此這篇關(guān)于Node.js中path模塊操作路徑的基本使用的文章就介紹到這了,更多相關(guān)node.js path模塊使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
用C/C++來(lái)實(shí)現(xiàn) Node.js 的模塊(二)
上篇文章的主要內(nèi)容講訴了用C/C++來(lái)實(shí)現(xiàn) Node.js 的模塊,本文更深一步繼續(xù)探討這個(gè)問(wèn)題,有需要的朋友可以參考下2014-09-09NodeJs中express框架的send()方法簡(jiǎn)介
這篇文章主要介紹了NodeJs中express框架的send()方法簡(jiǎn)介,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-06-06Node.js中Path 模塊的介紹和使用示例小結(jié)
Node.js path 模塊提供了一些用于處理文件路徑的小工具,下面通過(guò)本文給大家介紹Node.js中Path 模塊的介紹和使用示例小結(jié),感興趣的朋友跟隨小編一起看看吧2024-05-05Node.js中http模塊和導(dǎo)出共享問(wèn)題
這篇文章主要介紹了Node.js中http模塊和導(dǎo)出共享,通過(guò)?http?模塊提供的?http.createServer()?方法,就能方便的把一臺(tái)普通的電腦,變成一臺(tái)?web?服務(wù)器,從而對(duì)外提供?web?資源服務(wù),本文給大家詳細(xì)講解,需要的朋友可以參考下2022-10-10