process.cwd() points to the location of the symlink, not the bash script in
my folder.

I'm using this code for now.  It uses process.cwd() to find the directory
containing of the symlink, then adds the filename to that to get the path
of the actual symlink file, then resolves the symlink to find out where it
points to,  then strips off the end of the path to find the module folder
location.  (My module is called bace).

SYMLINKTARGET=$(dirname $0)
SYMLINKTARGET+=/bace
BACE_DIR="`realpath $SYMLINKTARGET`"
BACE_DIR=$( dirname "$BACE_DIR" )
BACE_DIR=$( dirname "$BACE_DIR" )
cd $BACE_DIR

This seems like a lot more work than should be necessary.  Also realpath is
not available in the linux distributions.  So the user will have to install
that.  This script will be called a lot in tight loops so I'm also worried
about performance.

I was hoping that this is a common problem that npm would somehow solve for
me.



On Sun, Aug 4, 2013 at 6:14 AM, Joel Brandt <[email protected]> wrote:

> By "project folder", I assume you mean "the folder the user is currently
> at in their terminal." If so, use process.cwd():
>   http://nodejs.org/api/process.html#process_process_cwd
>
> Hope that helps,
>   -- Joel
>
>
> On Saturday, August 3, 2013 12:24:20 PM UTC-7, Mark Hahn wrote:
>>
>> I'm using an npm bin config to create a symlink to a script in my project
>> folder.  When that bin script runs, it has a working directory of the dir
>> the symlink is in, not the project folder.  How do I find the project
>> folder location inside that bin script?
>
>  --
> --
> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> 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 [email protected].
> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to