CWD of an Node.js application started with upstart (Ubuntu)
Asked Answered
E

1

5

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?

Enclitic answered 7/10, 2010 at 19:39 Comment(0)
E
7

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

Enclitic answered 7/10, 2010 at 19:40 Comment(1)
__dirname is a variable that represents the directory of the file not the application. The process.cwd() is supposed to show the process' working directory. However, I'm running into the same thing where process.cwd() returns root always from upstart.Nader

© 2022 - 2024 — McMap. All rights reserved.