Node.js 应用程序的 CWD 由 upstart (Ubuntu) 启动

发布于 2024-09-26 17:29:28 字数 362 浏览 0 评论 0原文

我编写了一个 node.js 应用程序,在执行时需要从进程返回 CWD 才能读取磁盘上的文件。

当我直接使用实际应用程序目录中的节点启动应用程序时......

 #!sh
 node app.js

一切正常,并且“process.cwd()”返回良好的路径。但是,当脚本使用 upstart 启动,甚至直接使用其他目录中的节点“process.cwd()”返回时“/”在新贵和来自女巫的任何目录的情况下,我直接使用节点启动我的应用程序。所以 process.cwd() 似乎输出执行命令的目录。为什么?该怎么办?

I've coded an node.js app that when get executed need to return CWD from process to be able to read files on disk.

When I start the app directly with node in the actual app directory...

 #!sh
 node app.js

everything is working fine and "process.cwd()" return the good path. But when the script is started with upstart or even directly with node from an other directory "process.cwd()" return "/" in the case of upstart and whatever directory from witch I directly start my app with node. So process.cwd() seem to output the directory from witch the command is executed. Why? What to do?

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

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

发布评论

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

评论(1

迷途知返 2024-10-03 17:29:28

Node.js 提供了一个全局变量“__dirname”,它提供应用程序的实际路径。

Node.js provides a global variable "__dirname" that provide the actual path of your application.

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