2

I'm writing a daemon script for Linux Debian, and I'd need to be able to access the $NVM_BIN shell environment variable, or somehow reference the path to the current "default" Node version as set in nvm.

Several of these daemon scripts will be running on the system.

Since all these scripts can share the same Node version, I'd like to reference some variable that gets automatically updated when I install a new version of Node and define it as "default", without having to manually change the Node JS reference in each script.

Is this possible?

Thanks!

1 Answer 1

4

I've finally found a way to do it.

The first line of the shell script must be:

#!/bin/bash

(part of the problems I had was related to the fact that my first line was #!/bin/sh instead)

Then, to access nvm variables or commands you must first source them with:

source <your_path>/nvm/nvm.sh

(where <your_path> needs to be replaced with the path to your nvm folder).

Now you can get the path to the node folder in two ways.

1. Through a standard nvm variable

$NVM_BIN

2. Directly "asking" to nvm

NVM_BIN=<your_path>/`nvm version`/bin/

Nice.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.