$ pwd
/home/user1
$ mkdir dir
$ cat > dir/app.js
console.log (process.cwd ());
$ node dir/app.js
/home/user1
$ cd dir && node app.js
/home/user1/dir

Now suppose you have this code:

//app.js
var fs = require ("fs");
if (fs.existsSync ("settings.json")){
    doSomethingUseful ();
}else{
    //Warning!!
    saveToDatabaseDefaultSettings ();
}

And execute the main file with a relative path:

node dir/app

You will enter into the else case because settings.json is stored inside dirbut 
the cwd is not 
dir, so you expect the path ./dir/settings.json but in fact the path is 
./settings.json.

El lunes, 26 de agosto de 2013 15:05:10 UTC+2, ajlopez escribió:
>
> Gagle, can you write down a concrete use case?
>
>
> On Mon, Aug 26, 2013 at 9:59 AM, Gagle <gagl...@gmail.com <javascript:>>wrote:
>
>> Because it's local to the file, it doesn't work anywhere.
>>
>> El lunes, 26 de agosto de 2013 14:46:55 UTC+2, mks escribió:
>>
>>> __dirname is local to any file. It works everywhere.
>>>
>>  -- 
>> -- 
>> Job Board: http://jobs.nodejs.org/
>> Posting guidelines: 
>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>> You received this message because you are subscribed to the Google
>> Groups "nodejs" group.
>> To post to this group, send email to nod...@googlegroups.com<javascript:>
>> To unsubscribe from this group, send email to
>> nodejs+un...@googlegroups.com <javascript:>
>> For more options, visit this group at
>> http://groups.google.com/group/nodejs?hl=en?hl=en
>>  
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "nodejs" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to nodejs+un...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to