npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cloudinary-img-uploader

v2.0.4

Published

Cloudinary Image Uploader is a lightweight and efficient npm package designed for seamless integration with Node.js and Express applications. It simplifies the process of uploading images to Cloudinary, a powerful media management platform. This package p

Readme

cloudinary-img-uploader - NPM Package

This package allows you to upload files to Cloudinary using Express, Multer, and Cloudinary's API. It simplifies integrating Cloudinary file uploads into your Node.js applications.


Table of Contents

  1. Installation
  2. Setup
  3. Usage
  4. API
  5. Example

Installation

To install the cloudinary-img-uploader package, run the following command:

npm install cloudinary-img-uploader

You will also need the required dependencies:

npm install cloudinary multer multer-storage-cloudinary express dotenv

Setup

  1. Environment Variables: Ensure you have the following environment variables set up in your .env file:
CLOUDINARY_CLOUD_NAME=your-cloud-name
CLOUDINARY_API_KEY=your-api-key
CLOUDINARY_API_SECRET=your-api-secret

These credentials are necessary to connect to your Cloudinary account.

  1. Cloudinary Configuration: The CloudinaryUploader class uses Cloudinary's API to upload files. It is initialized with your Cloudinary credentials.

Usage

  1. Import the Package:
const CloudinaryUploader = require('cloudinary-img-uploader');
  1. Initialize CloudinaryUploader:

You need to create an instance of CloudinaryUploader by passing in your Cloudinary credentials from the .env file.

const uploader = new CloudinaryUploader({
  cloudName: process.env.CLOUDINARY_CLOUD_NAME,
  apiKey: process.env.CLOUDINARY_API_KEY,
  apiSecret: process.env.CLOUDINARY_API_SECRET,
});
  1. Set Up the Upload Middleware:

Use the getSingleUploaderMiddleware or getMultipleUploaderMiddleware methods to set up the file upload middleware.

For a single file upload:

const uploadMiddleware = uploader.getSingleUploaderMiddleware("custom", "uploads");

For multiple file uploads:

const uploadMiddleware = uploader.getMultipleUploaderMiddleware("images", "uploads");
  1. Set Up Express Route:

Use the middleware to handle file uploads in your Express routes.

const express = require("express");
const app = express();

app.post("/upload", uploadMiddleware, (req, res) => {
  try {
    if (!req.file) {
      return res.status(400).json({ error: "No file uploaded!" });
    }
    res.status(200).json({
      message: "File uploaded successfully!",
      fileUrl: req.file.path,
    });
  } catch (err) {
    console.error("Error during file upload:", err);
    res.status(500).json({
      error: "File upload failed!",
      details: err.message,
    });
  }
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server running on http://localhost:${PORT}`);
});

API

CloudinaryUploader(options)

Constructor to initialize CloudinaryUploader with Cloudinary API credentials.

Parameters:

  • options.cloudName: Your Cloudinary cloud name.
  • options.apiKey: Your Cloudinary API key.
  • options.apiSecret: Your Cloudinary API secret.

initializeUploader(folderName)

This method initializes the uploader with the folder name where uploaded images will be stored. The folder name is optional and defaults to uploads. Allowed file formats are restricted to jpg, png, and jpeg.

Parameters:

  • folderName: The folder in Cloudinary where files will be uploaded.

getSingleUploaderMiddleware(image, folderName)

This method returns a middleware for handling single file uploads.

Parameters:

  • image: The field name for the uploaded file (default: "image").
  • folderName: The folder name in Cloudinary (default: "uploads").

Returns a middleware function that you can use in your Express routes.

getMultipleUploaderMiddleware(images, folderName)

This method returns a middleware for handling multiple file uploads.

Parameters:

  • images: The field name for the uploaded files (default: "images").
  • folderName: The folder name in Cloudinary (default: "uploads").

Returns a middleware function that you can use in your Express routes.


Example

Here's a complete example of setting up and using the CloudinaryUploader with Express:

const express = require("express");
const CloudinaryUploader = require("cloudinary-img-uploader");
require("dotenv").config();

const uploader = new CloudinaryUploader({
  cloudName: process.env.CLOUDINARY_CLOUD_NAME,
  apiKey: process.env.CLOUDINARY_API_KEY,
  apiSecret: process.env.CLOUDINARY_API_SECRET,
});

const uploadMiddleware = uploader.getSingleUploaderMiddleware("custom", "uploads");

const app = express();

app.post("/upload", uploadMiddleware, (req, res) => {
  try {
    if (!req.file) {
      return res.status(400).json({ error: "No file uploaded!" });
    }
    res.status(200).json({
      message: "File uploaded successfully!",
      fileUrl: req.file.path,
    });
  } catch (err) {
    console.error("Error during file upload:", err);
    res.status(500).json({
      error: "File upload failed!",
      details: err.message,
    });
  }
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server running on http://localhost:${PORT}`);
});