Getting Passenger to use a custom Node script

I’ve been trying to get Node to work through Passenger (enabled in the domain settings). I managed to get the app up and running but have one final problem I can’t find the solution of (at least I hope it is, haha!).

I have an env file that I open using env-cmd, so that particular command will have to be executed before starting the app itself.

There’s a script in package.json that does exactly this: env-cmd -f ./env/dev.env node app.js. How do you get Passenger to execute that instead of just starting the app? If that isn’t possible, what do you suggest I do instead?

Thanks in advance!

If the app (or a dependency) is using env-cmd to customise the process environment you can copy the required vars from ./env/dev.env to your ~/.bashrc file preceded by an export command. This will set the custom environment variables for the entire user account.



# ~/.bashrc: executed by bash(1) for non-login shells.
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/" ] && \. "$NVM_DIR/"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

export FOO="BAR" # a custom environment variable

Quick test while still in shell:

$ source .bashrc
$ node
Welcome to Node.js v13.14.0.
Type ".help" for more information.
> console.log(process.env.FOO)
> .exit
$ _

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.