Programmable Media

Getting started with Cloudinary in Node.js (video tutorial)

Last updated: Jan-13-2025

Overview

Learn to get started with Cloudinary in a Node.js app. This tutorial covers setting up, configuring, and optimizing images using the Cloudinary Node.js SDK.

Video tutorial


View the code
You can find the code from this tutorial in GitHub.

Tutorial contents

This tutorial presents the following topics. Click a timestamp to jump to that part of the video.

Introduction to Cloudinary

Jump to this spot in the video  0:00 Discover the power of Cloudinary, a platform for image and video management that goes beyond simple uploads. Learn about features like background removal, dynamic cropping, resizing, and AI-driven content analysis in a Node.js app.

Set up Cloudinary

Jump to this spot in the video  0:24
  • Install the Cloudinary Node.js SDK using your preferred package manager e.g., npm install cloudinary.
  • Import Cloudinary using const cloudinary = require('cloudinary').v2.
  • Configure your account using cloudinary.config(), where you’ll input your cloud_name, api_key, and api_secret. Learn how to find these credentials in your Cloudinary dashboard.

Deliver an image from Cloudinary

Jump to this spot in the video  1:40 You can look for an image to deliver in your Media Library. There are some pre-uploaded ones or you can upload your own. Copy the public ID of the image to use in your script. Use the cloudinary.url() method to generate the delivery URL from the public ID.

Transform an image

Jump to this spot in the video  2:30 To transform an image, add a second argument, transformation, to the url method, specifying different transformations. For example, fetch_format: 'auto' delivers the best format based on the browser, quality: 'auto' compresses the image as much as possible without visual impact, and width:1200 resizes the image on the server side, reducing the number of bytes to deliver.

Upload an image programmatically

Jump to this spot in the video  4:16 To upload an image programmatically, you need to configure your API key and secret. Use environment variables to store these, as you shouldn't expose your API secret to anyone. Then you can use the cloudinary.uploader.upload() method to upload an image. For example, uploading a local image:

Transform the uploaded image

Jump to this spot in the video  7:08 In the same function, use the cloudinary.url() method as before, but with results.public_id instead of the hard coded public ID. For example:

Take a look at these code examples:


Keep learning

Related topics

If you like this, you might also like...

Configure the Node.js SDK
Install and configure the Cloudinary Node.js SDK
Captioning on Upload with Node.js
Save auto-generated captions to use as alt text with Node.js
Delete Assets with Node.js
Delete assets using various methods from the Node.js SDK

 

Cloudinary Academy

 

Check out the Cloudinary Academy for free self-paced Cloudinary courses on a variety of developer or DAM topics, or register for formal instructor-led courses, either virtual or on-site.

 

✔️ Feedback sent!

Rate this page: