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

lesca-node-bunnycdn

v0.0.22

Published

use bunny CDN api by node

Downloads

2,303

Readme

React React React React React NPM React BunnyCDN

Lesca Node BunnyCDN

A Node.js client library for BunnyCDN storage operations with TypeScript support. Perfect for file uploads, management, and integration with serverless functions like Netlify Functions.

Why use it?

  • 🚀 Easy to use - Simple API for BunnyCDN storage operations
  • 🔧 TypeScript support - Full type definitions included
  • 🌍 Multi-region support - Works with all BunnyCDN storage regions
  • 🔒 Environment variable support - Perfect for serverless environments
  • 📁 Folder organization - Organize files in custom folder structures
  • Lightweight - No unnecessary dependencies

Installation

npm install lesca-node-bunnycdn --save

Usage

Method 1: Using Environment Variables (Recommended for Netlify Functions)

Set environment variables in your Netlify dashboard or .env file:

BUNNY_STORAGE_ZONE=your-storage-zone
BUNNY_PASSWORD=your-password
BUNNY_REGION=SG
BUNNY_FOLDER_NAME=uploads
import BunnyCDN from 'lesca-node-bunnycdn';

// Upload a file (uses environment variables)
const uploadResult = await BunnyCDN.upload({
  buffer: yourBuffer, // or file: yourFile
});

// List files
const listResult = await BunnyCDN.list();

// Delete a file
const deleteResult = await BunnyCDN.deleteFile({
  ObjectName: 'filename.webp',
});

Method 2: Using install() Function

import BunnyCDN from 'lesca-node-bunnycdn';

// Configure once
BunnyCDN.install({
  storageZone: 'your-storage-zone',
  password: 'your-password',
  region: 'SG', // optional
  folderName: 'uploads', // optional
});

// Use throughout your application
const uploadResult = await BunnyCDN.upload({ buffer: yourBuffer });
const listResult = await BunnyCDN.list();

Method 3: Passing Configuration Parameters

import { upload, list, deleteFile } from 'lesca-node-bunnycdn';

// Pass configuration with each call
const uploadResult = await upload({
  buffer: yourBuffer,
  storageZone: 'your-storage-zone',
  password: 'your-password',
  region: 'SG',
  folderName: 'uploads',
});

Configuration Parameters

| Parameter | Type | Required | Default | Description | | ------------- | ------ | -------- | ------- | --------------------------------------------------- | | storageZone | string | Yes | - | Your BunnyCDN storage zone name | | password | string | Yes | - | Your BunnyCDN storage password | | region | string | No | 'SG' | Storage region (e.g., 'SG', 'NY', 'LA', 'UK', 'DE') | | folderName | string | No | '' | Folder path within the storage zone |

API Reference

upload(params)

Uploads a file to BunnyCDN storage.

Parameters:

  • file: Express multer file object (optional)
  • buffer: Buffer containing file data (optional)
  • Configuration parameters (optional - will override environment variables)

Returns:

Promise<{
  res: boolean;
  message: string;
  url?: string;
  error?: any;
}>;

Example:

const result = await BunnyCDN.upload({
  buffer: fs.readFileSync('image.jpg'),
});

if (result.res) {
  console.log('Upload successful:', result.url);
} else {
  console.error('Upload failed:', result.message);
}

list(configOverrides?)

Lists all files in the configured storage zone and folder.

Parameters:

  • configOverrides: Configuration parameters (optional)

Returns:

Promise<{
  res: boolean;
  message: string;
  files?: File[];
}>;

Example:

const result = await BunnyCDN.list();

if (result.res && result.files) {
  result.files.forEach((file) => {
    console.log('File:', file.ObjectName, 'URL:', file.Url);
  });
}

deleteFile(params)

Deletes a file from BunnyCDN storage.

Parameters:

  • ObjectName: File name to delete (optional)
  • href: Full URL of the file to delete (optional)
  • Configuration parameters (optional)

Returns:

Promise<{
  res: boolean;
  message: string;
}>;

Example:

// Delete by object name
const result = await BunnyCDN.deleteFile({
  ObjectName: 'image.webp',
});

// Or delete by URL
const result = await BunnyCDN.deleteFile({
  href: 'https://your-zone.b-cdn.net/uploads/image.webp',
});

install(params)

Sets up default configuration for the library.

Parameters:

  • storageZone: Your BunnyCDN storage zone name
  • password: Your BunnyCDN storage password
  • region: Storage region (optional)
  • folderName: Folder path within storage zone (optional)

Example:

BunnyCDN.install({
  storageZone: 'my-zone',
  password: 'my-password',
  region: 'SG',
  folderName: 'uploads',
});

TypeScript Support

This library includes full TypeScript definitions. Import types as needed:

import BunnyCDN from 'lesca-node-bunnycdn';
import type { InstallParams, UploadParams, File } from 'lesca-node-bunnycdn/dist/type';

Error Handling

All methods return promises that resolve to objects with a res boolean field indicating success or failure:

const result = await BunnyCDN.upload({ buffer: yourBuffer });

if (result.res) {
  // Success
  console.log(result.message, result.url);
} else {
  // Error
  console.error(result.message, result.error);
}

Netlify Functions Example

// netlify/functions/upload.ts
import BunnyCDN from 'lesca-node-bunnycdn';

export const handler = async (event, context) => {
  try {
    const buffer = Buffer.from(event.body, 'base64');

    // Configuration will be read from environment variables
    const result = await BunnyCDN.upload({ buffer });

    return {
      statusCode: 200,
      body: JSON.stringify(result),
    };
  } catch (error) {
    return {
      statusCode: 500,
      body: JSON.stringify({ error: 'Upload failed' }),
    };
  }
};

Supported Regions

  • SG - Singapore (default)
  • NY - New York
  • LA - Los Angeles
  • UK - United Kingdom
  • DE - Germany

Features

  • ✅ Upload files to BunnyCDN storage
  • ✅ List files in storage zone
  • ✅ Delete files from storage
  • ✅ Support for different regions
  • ✅ Folder organization
  • ✅ Full TypeScript support
  • ✅ Environment variable configuration
  • ✅ Automatic file extension handling (.webp)
  • ✅ UUID-based filename generation
  • ✅ Perfect for serverless functions

License

MIT

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Features

  • maintain if necessary