Search code examples
node.jsreactjsstrapiheadless-cms

unable to use environment variables in strapi


I am trying to connect a MongoDB URI to the strapi backend. I am able to connect with the main URL but when I created a .env.development variable, I am not able to connect to the database.

 {
  "defaultConnection": "default",
  "connections": {
    "default": {
      "connector": "mongoose",
      "settings": {
        "uri": "${process.env.DATABASE_URI || ''}"
      },
      "options": {
        "ssl": true
      }
    }
  }
}

Solution

  • Ok, new plan.

    try that :

    npm install --save dotenv

    require('dotenv').config()
    
    {
      "defaultConnection": "default",
      "connections": {
        "default": {
          "connector": "mongoose",
          "settings": {
            "uri": `${process.env.DATABASE_URI || ''}`
      },
      "options": {
        "ssl": true
      }
    }
    

    } }