I am trying to import cloudinary to my project, and in their documentation it says that I have to use require and specify the version to v2 like this const cloudinary = require("cloudinary").v2;
. However, I have specified that my type in package.json as 'module', so I cannot use require I only have to say import. so, my question is how do I specify the version to v2. currently, I can upload to the cloudinary server, but I cannot get back the link to it. here is my cod:
my configuration
import multer from "multer";
import cloudinary from "cloudinary";
import { CloudinaryStorage } from "multer-storage-cloudinary";
import dotenv from "dotenv";
cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_KEY,
api_secret: process.env.CLOUDINARY_SECRET,
});
const storage = new CloudinaryStorage({
cloudinary: cloudinary,
params: {
folder: "ecommerce",
},
});
const upload = multer({ storage: storage });
my route
productsRoutes.post("/products", upload.single("image"), async (req, res) => {
console.log(req.file);
});
currently, the console log prints nothing when I submit the image, but it does upload it to the server.
sorry if my question is badly formatted, and any help is greatly appreciate it.