在nodejs传递地址时,何时放置'/'在目录之间以及何时放置' \\' 。为什么我们要在写作地址之前放置点(。)

发布于 2025-02-07 08:15:14 字数 56 浏览 1 评论 0原文

在nodejs中传递地址时,何时在目录之间和何时放置'\'。为什么我们要在写作地址之前放置点(。)

While passing address in nodejs, when to place '/' between directories and when to place '\' . And why do we place dot(.) before writing addresses

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等待圉鍢 2025-02-14 08:15:14

路径软件包提供功能,因此您不必担心需要哪种目录分离器使用。

const path = require('path');
path.join(parentDir, childDir);

dot代表当前目录IE

project index file path: /home/user/projects/project-name/index.js
you are in <project-name> folder
so index file path will be ./index.js

path package provides functionality so that you don't need to worry about what directory separator you need to use.

const path = require('path');
path.join(parentDir, childDir);

And dot represents current directory i.e.

project index file path: /home/user/projects/project-name/index.js
you are in <project-name> folder
so index file path will be ./index.js
情栀口红 2025-02-14 08:15:14

在UNIX/Linux环境中,您将前向斜杠作为文件夹Seperator。

例如,

在Windows系统中,您将BackSlashes用作文件夹Seperator,因为BackSlash也是字符串中的逃生字符,因此您应该逃脱后挡板。

例如C:\ users \ user \ image.jpg

您使用的。对于相对路径。
例如,如果您的脚本在/home/home/user/中运行,并且您想访问image.jpg,则可以通过./image.jpg进行。

有关更多信息: https://nodejs.org/api/path.html

In a Unix/Linux environments you place a forward slash as a folder seperator.

e.g. /home/user/image.jpg

In a Windows system you use backslashes as folder seperators, since a backslash is also an escape character in a string you should escape the backslash.

e.g. C:\users\user\image.jpg

You use a . for relative paths.
e.g. if your script runs in /home/user/ and you want to access image.jpg you can do so by ./image.jpg

for more info: https://nodejs.org/api/path.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文