Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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?

like image 909
plehoux Avatar asked Oct 07 '10 19:10

plehoux


1 Answers

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

like image 73
plehoux Avatar answered Sep 30 '22 12:09

plehoux