简体   繁体   English

Node.js应用程序的CWD以upstart(Ubuntu)开头

[英]CWD of an Node.js application started with upstart (Ubuntu)

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. 我编写了一个node.js应用程序,当执行时需要从进程返回CWD才能读取磁盘上的文件。

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. 一切正常,“process.cwd()”返回好路径。 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. 但是当脚本以upstart启动时,甚至直接与其他目录中的节点“process.cwd()”一起返回“/”,在upstart的情况下,以及来自巫婆的任何目录,我直接用节点启动我的应用程序。 So process.cwd() seem to output the directory from witch the command is executed. 所以process.cwd()似乎从执行命令输出目录。 Why? 为什么? What to do? 该怎么办?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM