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 > Even in shell scripts, "$PWD" is not as good as "$(pwd)" for this > If you want the real path when running in a directory path that > var fs = require('fs') > If you want to know the dir that a script lives in, check the > var scriptLivesInThisDir = __dirname > To get the real path of the cwd, you could do: > fs.realpath(process.cwd(), function (er, real) { ... }) > There is no way in your script to detect if it was loaded via a > To find a file that exists in the same folder as your script, you can > 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') > 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.
| ||||||||||||||