Upload an image to Cloudinary using the Node SDK
By Mike Street
Install the library using npm or yarn
npm install cloudinary --save
Next, we need to include and initialise the library - for this code we are going to be using
v2 of the Node SDK.
In the example below, I've used the dotenv package to avoid having my credentials committed to the repository.
const cloudinary = require('cloudinary').v2;
To make this more easily portable, I created a module with my Cloudinary initialisation in. This allows me to include the following for a ready-to-go Cloudinary API
const cloudinary = require('./cloudinary');
With the library loaded, you can upload your image with the path to the file. This can be a remote or local path. The
public_id is the path where you want the image to be uploaded to.
const cloudinary = require('cloudinary').v2
cloud_image = cloudinary.uploader.upload(