Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Current directory is a symlink?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Isaac Schlueter  
View profile  
 More options Feb 27 2011, 3:49 pm
From: Isaac Schlueter <i...@izs.me>
Date: Sun, 27 Feb 2011 12:49:53 -0800
Local: Sun, Feb 27 2011 3:49 pm
Subject: Re: [nodejs] Re: Current directory is a symlink?
Another thing: if you're going to be realpathing a lot, and don't
expect the file system to change out from under you while you do, you
can pass a "cache" object to fs.realpath, and it will use that to
avoid doing unnecessarily repetitive lstat calls.  Check out how it's
used in lib/module.js.

--i

On Sun, Feb 27, 2011 at 12:48, Isaac Schlueter <i...@izs.me> wrote:
> To get the current working directory in node, use process.cwd().  The
> PWD environ is not reliable.

>    PWD=pwned node -e 'process.env.PWD'  // does this output the
> current working dir?

> Even in shell scripts, "$PWD" is not as good as "$(pwd)" for this
> reason.  Do not rely on it.

> If you want the real path when running in a directory path that
> contains symlinks, use:

>    var fs = require('fs')
>    fs.realpath(p, function (er, real) { ... })
>    // or
>    var real = fs.realpathSync(p) // throws on error

> If you want to know the dir that a script lives in, check the
> __dirname free variable.  It should already be realpathed.

>    var scriptLivesInThisDir = __dirname

> To get the real path of the cwd, you could do:

>    fs.realpath(process.cwd(), function (er, real) { ... })
>    // or
>    var real = fs.realpathSync(process.cwd())

> There is no way in your script to detect if it was loaded via a
> symlink.  It always behaves as if it was loaded from its actual real
> file location.

> To find a file that exists in the same folder as your script, you can
> use path.resolve() against the __dirname.

>    var tsFile = path.resolve(__dirname, '.timestamp')

> To find it in the cwd, you can do:

>    var ts = path.resolve(process.cwd(), '.timestamp')

> To find it in the real path of the cwd, you can do:

>    var ts = path.resolve(fs.realpathSync(process.cwd()), '.timestamp')
>    // or, equivalently:
>    var ts = fs.realpathSync(path.resolve(process.cwd(), '.timestamp'))

> Does that answer your question(s)?

> --i


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.