> ## Documentation Index
> Fetch the complete documentation index at: https://cloudinary.com/documentation/llms.txt
> Use this file to discover all available pages before exploring further.

# Delete assets with the Node.js SDK (video tutorial)

[githublink]: https://github.com/cloudinary-devs/delete-assets-node

## Overview

In this tutorial, you'll learn about the different ways to delete your resources from Cloudinary, including a deep dive into the Node.js SDK methods.

To follow along with the tutorial, clone the [delete-assets-node GitHub repo](https://github.com/cloudinary-devs/delete-assets-node) and see the instructions in the [README](https://github.com/cloudinary-devs/delete-assets-node/blob/main/README.md).

## Video tutorial

  This video is brought to you by Cloudinary's video player - embed your own!Use the controls to set the playback speed, navigate to chapters of interest and select subtitles in your preferred language.

> **TIP**: :title=View the code

You can find the code from this tutorial in [GitHub][githublink].
## Tutorial contents
This tutorial presents the following topics. Click a timestamp to jump to that part of the video.
### Delete assets using the Console
{table:class=tutorial-bullets}|  |  
| --- | --- |
|{videotime:id=media :min=0 :sec=00 :player=cld} | There are many ways to delete assets from Cloudinary.  In the [Cloudinary Console](https://console.cloudinary.com/console), you can delete individual or multiple assets from your [Media Library](https://console.cloudinary.com/console/media_library/search), or, in the Settings, you can bulk delete many assets based on various criteria.

### Delete assets using the Node.js SDK
{table:class=tutorial-bullets}|  |  
| --- | --- |
|{videotime:id=media :min=0 :sec=56 :player=cld} | As deleting assets is a backend operation, you need to set your Cloudinary API environment variable, which you can copy from the **Dashboard** page in the [Cloudinary Console](https://console.cloudinary.com/console). Paste it into a **.env** file, but don't submit this to version control as it contains your API secret, which should never be exposed.|
> **NOTE**:
>
> You can no longer access your full credentials directly from the Dashboard. Find your **Cloud name** on the Dashboard, and all credentials, including **API Key**, **API Secret**, and **API environment variable**, on the [API Keys](https://console.cloudinary.com/app/settings/api-keys) page of the Cloudinary Console Settings.
### Delete one asset at a time
{table:class=tutorial-bullets}|  |  
| --- | --- |
|{videotime:id=media :min=1 :sec=17 :player=cld} | To delete one asset at a time, you can use the [destroy method of the upload API](image_upload_api_reference#destroy). Pass in the public ID of the asset to delete. If you don't pass in any other parameters, it is assumed that the asset is an image of [delivery type](image_transformations#delivery_types) 'upload'.|

```nodejs
cloudinary.uploader
  .destroy('docs/vegetables')
  .then(result => console.log(result));
```

### Delete an authenticated video
{table:class=tutorial-bullets}|  |  
| --- | --- |
|{videotime:id=media :min=2 :sec=06 :player=cld} | If the asset you want to delete is not an image or of delivery type 'upload', you need to include the `resource_type` and/or `type` parameters. For example, to delete an authenticated video:|

```nodejs
cloudinary.uploader
    .destroy('docs/stream', {resource_type: 'video', type: 'authenticated'})
    .then(result => console.log(result));
```

### Invalidate the cache
{table:class=tutorial-bullets}|  |  
| --- | --- |
|{videotime:id=media :min=2 :sec=25 :player=cld} | Even if you delete assets from your product environment they may still be accessible if they have been delivered and are cached on the CDN. To invalidate the cache, specify `invalidate: true`.|

```nodejs
cloudinary.uploader
    .destroy('docs/lemonade', {resource_type: 'video', invalidate: true, type: 'authenticated'})
    .then(result => console.log(result));
```

### Delete multiple assets at a time
{table:class=tutorial-bullets}|  |  
| --- | --- |
|{videotime:id=media :min=2 :sec=52 :player=cld} | To delete more than one asset at a time, use one of the [delete resources methods of the admin API](admin_api#delete_resources). Use the `delete_resources` method if you know the public IDs of the assets you want to delete.|

```nodejs
cloudinary.api
    .delete_resources(['docs/strawberries', 'docs/owl'])
    .then(result=>console.log(result));
```

### Delete images by public ID prefix
{table:class=tutorial-bullets}|  |  
| --- | --- |
|{videotime:id=media :min=3 :sec=16 :player=cld} | If all the assets you want to delete have public IDs that follow a convention (start with the same prefix), you can use the `delete_resources_by_prefix` method. For example, to delete all images of type 'upload' that have a public ID starting `docs/`:|

```nodejs
cloudinary.api
    .delete_resources_by_prefix('docs/')
    .then(result=>console.log(result));
```

### Delete authenticated videos by public ID prefix
{table:class=tutorial-bullets}|  |  
| --- | --- |
|{videotime:id=media :min=3 :sec=38 :player=cld} | To delete authenticated videos by public ID prefix, set the `resource_type` to `video` and `type` to `authenticated` as [before](#delete_an_authenticated_video): |

```nodejs
cloudinary.api
    .delete_resources_by_prefix('docs/', {resource_type: 'video', type: 'authenticated'})
    .then(result=>console.log(result)); 
```

### Delete authenticated images by public ID prefix
{table:class=tutorial-bullets}|  |  
| --- | --- |
|{videotime:id=media :min=3 :sec=53 :player=cld} | To delete authenticated images by public ID prefix, set the `type` to `authenticated`.  There's no need to set `resource_type` to `image` as that's the default.|

```nodejs
cloudinary.api
    .delete_resources_by_prefix('docs/', {type: 'authenticated'})
    .then(result=>console.log(result)); 
```

### Delete all assets of a particular type
{table:class=tutorial-bullets}|  |  
| --- | --- |
|{videotime:id=media :min=4 :sec=10 :player=cld} | Use the `delete_all_resources` method to delete all assets matching a particular [asset type](upload_parameters#asset_types) and [delivery type](image_transformations#delivery_types). For example, to delete all Facebook images: |

```nodejs
cloudinary.api
    .delete_all_resources({type: 'facebook'})
    .then(result=>console.log(result)); 
```

### Delete all assets with the same tag
{table:class=tutorial-bullets}|  |  
| --- | --- |
|{videotime:id=media :min=4 :sec=35 :player=cld} | Use the `delete_resources_by_tag` method to delete all assets that have the specified tag. By default, all images are deleted regardless of their delivery type. To delete videos, set the `resource_type` to `video` (as in the [next example](#delete_only_derived_versions_of_assets)).|

```nodejs
cloudinary.api
    .delete_resources_by_tag('mine')
    .then(result=>console.log(result));
```

### Delete only derived versions of assets
{table:class=tutorial-bullets}|  |  
| --- | --- |
|{videotime:id=media :min=5 :sec=09 :player=cld} | You can delete only the derived versions of assets and keep the original intact, by setting the `keep_original` parameter to true. |

```nodejs
cloudinary.api
    .delete_resources_by_tag('mine', {resource_type: 'video', keep_original: true})
    .then(result=>console.log(result));
```

### Delete specific derived versions of assets
{table:class=tutorial-bullets}|  |  
| --- | --- |
|{videotime:id=media :min=5 :sec=35 :player=cld} | The [resource](admin_api#get_details_of_a_single_resource_by_public_id) method returns details of derived versions of assets. You can use the IDs returned for each of the derived versions in the `delete_derived_resources` method to delete only those versions.|

```nodejs
cloudinary.api
    .resource('docs/stream', {resource_type: 'video'})
    .then(result=>console.log(result));

cloudinary.api
    .delete_derived_resources(['76b6ee3a81e20e110ab81d368d18ff53', '349bfe6c9813708c5398f5cadf391a7d'])
    .then(result=>console.log(result));
```

## Keep learning

> **READING**:
>
> * Take our free self-paced [Introduction for Node.js Developers](https://training.cloudinary.com/courses/introduction-for-api-users-developers) course in the Cloudinary Academy.

> * Learn more about [deleting assets](delete_assets).

> * Find out how to [restore deleted assets](backups_and_version_management#restoring_deleted_assets_from_backup) from backup.

> * Discover what else you can do with the Cloudinary [Node.js SDK](node_integration).

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

  
  
  
    Configure the Node.js SDK
    Install and configure the Cloudinary Node.js SDK 
  

  
  
  
    Get Started in Node.js
    Get started with Cloudinary in Node.js, including setup and image optimization 
  

  
  
  
    List Images in Next.js
    List images using the Next.js app router and Node.js SDK 
  

&nbsp;

&nbsp;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.
&nbsp;