node.js中的path.join方法使用說明
方法說明:
將多個(gè)參數(shù)組合成一個(gè) path (詳細(xì)請(qǐng)看例子)
語(yǔ)法:
path.join([path1], [path2], [...])
由于該方法屬于path模塊,使用前需要引入path模塊(var path= require(“path”) )
例子:
path.join('/foo', 'bar', 'baz/asdf', 'quux', '..')
// returns
'/foo/bar/baz/asdf'
path.join('foo', {}, 'bar')
// throws exception
TypeError: Arguments to path.join must be strings
源碼:
// windows version
exports.join = function() {
function f(p) {
if (!util.isString(p)) {
throw new TypeError('Arguments to path.join must be strings');
}
return p;
}
var paths = Array.prototype.filter.call(arguments, f);
var joined = paths.join('\\');
// Make sure that the joined path doesn't start with two slashes, because
// normalize() will mistake it for an UNC path then.
//
// This step is skipped when it is very clear that the user actually
// intended to point at an UNC path. This is assumed when the first
// non-empty string arguments starts with exactly two slashes followed by
// at least one more non-slash character.
//
// Note that for normalize() to treat a path as an UNC path it needs to
// have at least 2 components, so we don't filter for that here.
// This means that the user can use join to construct UNC paths from
// a server name and a share name; for example:
// path.join('//server', 'share') -> '\\\\server\\share\')
if (!/^[\\\/]{2}[^\\\/]/.test(paths[0])) {
joined = joined.replace(/^[\\\/]{2,}/, '\\');
}
return exports.normalize(joined);
};
相關(guān)文章
在Debian(Raspberry Pi)樹莓派上安裝NodeJS的教程詳解
在樹莓派上運(yùn)行NodeJS并不需要特別的配置,你只需要確??梢杂胦penssh遠(yuǎn)程連接到你的樹莓派就ok了,關(guān)于在Debian(Raspberry Pi)樹莓派上安裝NodeJS的方法,大家可以通過本文了解下2017-09-09基于nodejs的微信JS-SDK簡(jiǎn)單應(yīng)用實(shí)現(xiàn)
這篇文章主要介紹了基于nodejs的微信JS-SDK簡(jiǎn)單應(yīng)用實(shí)現(xiàn),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2019-05-05npm?i報(bào)錯(cuò)以及解決方案實(shí)戰(zhàn)案例
npm在前端開發(fā)流程中提供了非常完善的自動(dòng)化工具鏈,但是同樣由于其復(fù)雜性導(dǎo)致有很多奇奇怪怪的問題,下面這篇文章主要給大家介紹了關(guān)于npm?i報(bào)錯(cuò)以及解決方案的相關(guān)資料,需要的朋友可以參考下2022-07-07nodejs中簡(jiǎn)單實(shí)現(xiàn)Javascript Promise機(jī)制的實(shí)例
這篇文章主要介紹了nodejs中簡(jiǎn)單實(shí)現(xiàn)Javascript Promise機(jī)制的實(shí)例,本文在nodejs中簡(jiǎn)單實(shí)現(xiàn)一個(gè)promise/A 規(guī)范,需要的朋友可以參考下2014-12-12npm?install總是卡住不動(dòng)問題的解決辦法
在我們安裝完Node.js之后,需要使用npm命令來(lái)安裝一些工具,下面這篇文章主要給大家介紹了關(guān)于npm?install總是卡住不動(dòng)問題的解決辦法,需要的朋友可以參考下2022-05-05