时间:2021-05-26
方法说明:
将多个参数组合成一个 path (详细请看例子)
语法:
复制代码 代码如下:
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);
};
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
一、安装npm镜像(1)下载node.js,配置node.js的环境变量检测PATH环境变量是否配置了Node.js,点击开始=》运行=》输入"cmd"=>输入
场景在官方提供的文档中提供方式,app.module.tsServeStaticModule.forRoot({rootPath:path.join(proce
什么是Node.js的模块(Module)?在Node.js中,模块是一个库或框架,也是一个Node.js项目。Node.js项目遵循模块化的架构,当我们创建了
本文实例讲述了node.js中fs文件系统模块的使用方法。分享给大家供大家参考,具体如下:node.js中为我们提供了fs文件系统模块,实现对文件或目录的创建,
记录一些Node.js应用中的小知识点,如果你Google/Baidu“Node.js如何判断文件是否存在”发现给出的很多答案还是使用的fs.exists,这里