How to use .env variables in cron.js

Hello,

Iā€™m using strapi with Docker.
How can I use my .env variables in app/config/functions/cron.js?

process.env.VAR_NAME doesnt working for me. :frowning:

Screen Shot 2021-05-10 at 21.43.11

Ok, I need add VAR_NAME on my docker-compose.yml environment.

environment:
      MY_VAR: ${MY_VAR}

Now, I can access process.env.MY_VAR.

Additionally, if you really want to use the .env file, You can add this to your docker-compose.yml file:

env_file:
  - <path_to_file>/.env

So if docker-compose.yml lives in the same directory as .env then you can leave out <path_to_file>/ in my example above.

1 Like

Very useful, @Richard_Nsama.
Thank you!

1 Like

My pleasure!