I'm having several issues with using the env file for certain projects in node, mainly Nuxt3.

Im currently running nuxt3 this way node -r dotenv/config .output/server/index.mjs via pm2. This loads the .env file and works great! But.. Nuxt3 does not require npm instal everything is builtin the .output (except dotenv grrr)

For example i need to change the PORT number or add other variables to the nuxt3 node execution, and i could do this PORT=3002 node .output/server/index.mjs but it would be so nice if the .env variables were automatically added.

bonus: add PORT from pm2 settings here as well.

Example script to add to .sh file

#!/usr/bin/env sh

# Load variables from .env file. (only need to add the path to site dir here)
export $(cat ./.env | grep -v ^# | xargs) >/dev/null

Why and how this exactly happens is a mix of Nuxt3 having 'advanced' options for configurations and pm2 that is started from another directory. 🤷🏻‍♂️

You may use @ to mention someone.

NODEJS: PM2 - Load variables from .env file in the pm2 .sh script.

1 total vote
  • Dennis moved item to board Planned

    2 weeks ago
  • Dennis moved item to board Under review

    2 weeks ago
  • SMIT. moved item to project Site Level Requests

    1 month ago
  • SMIT. created the item

    1 month ago