Search code examples
node.jslinuxdotenvnode-commandernode-pkg

Where do compiled NodeJs apps read the dotenv file from at execute time?


I am writing a commanderjs app, that uses dotenv. The app is that is compiled using pkg .

I have compiled the app for linux and moved the binary to /usr/local/bin, for it to be available on my PATH.

I am running the app from a shell script in ~/testing/myscript.sh

When I run the script from e.g. ~/testing where does the compiled app read the .env file from?


Solution

  • It reads the .env from the executing directory, in this case ~/testing/.env

    This was originally failing because I had named the file myapp.env, the file must be called .env.

    Alternatively, the config path can be set using a path in a object passed to .config():

    dotenv.config({path:'myapp.env'});