Last updated: Dec-11-2024
On this page:
Overview
Learn how to list images using the Next.js app router and the Cloudinary Node.js SDK. Search for assets using queries or by tag, and display them in a Next.js application rendered using React Server Components (RSC).
Video tutorial
Tutorial contents
This tutorial presents the following topics. Click a timestamp to jump to that part of the video.
Introduction
0:00 | Getting images into Cloudinary is easy but what about getting them out? You can use the Search API and Cloudinary Node.js SDK to display them in your Next.js app router application. |
Intro to App router in Next.js
0:24 | The Next.js app router brings some big changes and improvements to developer experience. The introduction of server vs client components is a key part of this. Client components behave like a typical React component, whereas server components offer the ability to do data fetching from within the component. |
Configure Home page for data fetching
0:50 | By default, pages and components will be server components. You can turn the Home page into an asynchronous component by adding the async tag in front of the function name, making it possible to use await for data fetching. |
Add search requests using the Cloudinary Node.js SDK
1:17 | Install and configure the Cloudinary Node.js SDK to be able to use it from your server designated React component. Add your SDK code inside your asynchronous page component to perform a search. For example to find all images with "converse" in the name: |
Search for images by tag
2:10 | Instead of returning all images or images by name, you can also search for images by tag. For example to find images with the tag "sneakers": |
Use returned images on your page
2:24 | Use the returned Cloudinary images on your page by looping through the returned images. First, destructure the returned resources to get the resources array from the JSON. Use map to iterate through the resources array. If using typescript, reference the CloudinaryResource and define this as an interface with public_id and secure_url as strings. Update your list items to reference the public_id as the key and secure_url as the image src. |
Take it further
3:27 | Take it further by learning all about how to add Cloudinary optimizations and transformations using Next Cloudinary. |
Keep learning
Related topics
- Find out more about image and video transformations.
- Watch more Dev Hints videos on the Cloudinary YouTube channel.
If you like this, you might also like...
Optimization Tips
Tips for delivering optimized imagesUpload Assets with Server Actions
Upload assets to Cloudinary using Next.js Server ActionsOptimize Videos in Next.js
Optimize delivery of videos in a Next.js app
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.
✖️