Search code examples
javascriptnode.jsexpresscloudinarydotenv

Cloudinary configuration is not read data from .env file


I'm using Cloudinary with my node.js project...

The issue is cloudinary.config is not reading data from .env file, I have to type them directly!

const cloudinary = require("cloudinary");

cloudinary.config({
  cloud_name: process.env.CLOUD_NAME,
  api_key: process.env.CLOUD_API_KEY,
  api_secret: process.env.CLOUD_API_SECRET,
});

cloudinary.v2.uploader.upload(
  file.tempFilePath,
  { folder: "test" },
  async(err, result) => {
    if(err) throw err;
    console.log(result);
  }
);

I'll be thankful if anyone can help 🙏🏻


Solution

  • Issue is solved with adding require("dotenv").config(); to the beginning of the same file which contains cloudinary.config