Initial Setup
It is recommended to initialize the "cloudinaryConfig " & "imageUploadMiddleware" in the index.js
or root file of your application.
index.js
// import express, dotenv and anything else that you need
// import "cloudinaryConfig" & "imageUploadMiddleware" from 'express-cloudinary-image-handler'
dotenv.config()
const app = express()
// Configure Cloudinary settings
cloudinaryConfig({
cloudName: process.env.CLOUDINARY_CLOUD_NAME,
apiKey: process.env.CLOUDINARY_API_KEY,
apiSecret: process.env.CLOUDINARY_API_SECRET
})
// Initialize the imageUploadMiddleware with the express app instance
imageUploadMiddleware(app)
ℹ️
Make sure that you initialize the "imageUploadMiddleware" before defining the routes where you intend to upload images.