Search code examples
strapi

Strapi cms, where to put the environment variables?


I am using stripe 3.0.0-beta.18.4 and there is a file config/environments/development/database.json

with this structure:

"settings": {
    "client": "mysql",
    "host": "${process.env.DATABASE_HOST || '127.0.0.1'}",
    "port": "${process.env.DATABASE_PORT || 27017}",
    "database": "${process.env.DATABASE_NAME || 'strapi'}",
    "username": "${process.env.DATABASE_USERNAME || ''}",
    "password": "${process.env.DATABASE_PASSWORD || ''}"
},

however, I can not find where to set that DATA_HOST data, I tried to write DATABASE_HOST="mydb" in a created .env file in root, but it does not work, I would like to find where to put those environment variables to get them work with the process.env.

Thanks in advance


Solution

  • What you can simply do is instead of relying on the bootstrap function to load your dotenv you can create a server.js file as follows.

    const dotenv = require('dotenv');
    const strapi = require('strapi');
    
    dotenv.config();
    strapi().start();
    

    and update your npm startscript to run node ./server.js instead of strapi start

    We will certainly revisit the current implementation in the future but this is a good workaround