How use environment variables

System Information
  • Strapi Version:
  • Operating System:
  • Database:
  • Node Version:
  • NPM Version:
  • Yarn Version:

I’m using nodemailer as the email provider, and when using the env function, it returns undefined. For example:

module.exports = ({ env }) => ({
email: {
    provider: env('EMAIL-PROVIDER'),
    providerOptions: {
      host: env('EMAIL-HOST'),
      port: env('EMAIL-PORT'),
      auth: {
        user: env('EMAIL-USER'),
        pass: env('EMAIL-PASS'),
    settings: {
      defaultFrom: env('EMAIL-USER'),
      defaultReplyTo: env('EMAIL-USER'),

It turns out that all those environment variables return undefined, therefore the provider does not work, I must clarify that I have a file in /config/ , and in that same location I have the file plugins.js where I export the previous module. How use .env files in strapi ?. Any example?

I usually put .env file at the root of the project directory.

Fill your environment variables with each corresponding values :


Thanks, it worked, the problem was that I was adding an extension to .env like for example:

Nice! Happy to help.