# bunnycdnjs

> Tool for BunnyCDN

Latest version **1.0.6** (published 2021-10-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install bunnycdnjs
pnpm add bunnycdnjs
yarn add bunnycdnjs
bun add bunnycdnjs
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2021-10-30 |
| First published | 2021-10-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 52 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | iKaio |
| Maintainers | ikaiodev |
| Keywords | bunnycdn, cdn |

## Links

- npm: https://www.npmjs.com/package/bunnycdnjs
- Repository: https://github.com/iKaio/bunnyjs
- Homepage: https://github.com/iKaio/bunnyjs#readme
- Issues: https://github.com/iKaio/bunnyjs/issues
- npm.io page: https://npm.io/package/bunnycdnjs

## Dependencies (1)

- [request](https://npm.io/package/request.md) ^2.88.2

## Recent versions

- 1.0.6 (latest) — 2021-10-30
- 1.0.5 — 2021-10-29
- 1.0.4 — 2021-10-28
- 1.0.3 — 2021-10-28
- 1.0.2 — 2021-10-27
- 1.0.1 — 2021-10-27
- 1.0.0 — 2021-10-27

## README

# BunnyJS / BunnyCDNJS

is a unoficial NodeJS client for the BunnyCDN API.

# Why ?

I always use BunnyCDN in my projects, but there's no oficial library for NodeJS, so i decide to make my own.

# Installation

With NPM:

```cli
npm i bunnycdnjs
```

yarn soon, sorry

# Get started

Using Require:

```js
const { BunnyStorageClient } = require("bunnycdnjs");
```

Using Import:

```ts
import { BunnyStorageClient } from "bunnycdnjs";
```

# Create Storage

You can find your apiKey at: `FTP & API Access > Password`

```js
const CDN = new BunnyStorageClient({
  apiKey: process.env.BUNNY_STORAGE_PASSWORD_KEY, // eg: "515qdnsd-3ghc-1c43-bd339jff9ga7-cd89-4b6f"
  storageZoneName: "myassets",
  cdnLocation: "New York",
});
```

# List Usage

```js
async function ListMyStorageRootFolder() {
  let RootFiles = await CDN.List(".");

  if (RootFiles.Data) {
    for (const File of RootFiles.Data) {
      console.log(`Name: ${File.ObjectName} Size: ${File.Length}`);
    }
  } else if (RootFiles.Error) {
    console.log(RootFiles.Error);
  }
}

ListMyStorageRootFolder();
```

# Download Usage

```js
async function SaveMyAssetsLocally() {
  let AssetsFiles = await CDN.List("Assets");

  if (AssetsFiles.Data) {

    for (const File of AssetsFiles.Data) {
      await CDN.Download("Assets", File.ObjectName);
      // Saved at: downloads/Assets
  
      // OR
  
      await CDN.Download("Assets", File.ObjectName, "media", File.ObjectName);
      // Saved at: media
    }

  } else if (AssetsFiles.Error) {
    console.log(AssetsFiles.Error);
  }
}

SaveMyAssetsLocally();
```

# Upload Usage

```js
async function SaveMyAssetsRemotelly() {
  let LocalAssetsFiles = fs.readdirSync("LocalAssets");

  for (const FileName of LocalAssetsFiles) {
    let content = fs.createReadStream("LocalAssets/" + FileName);
    let uploadResult = await CDN.Upload("Assets", FileName, content);

    if (uploadResult.Error) {
      console.log(FileName, "upload failed");
    }
  }
}

SaveMyAssetsRemotelly();
```

# Delete Usage

```js
async function ClearMyRemoteAssetsFolder() {
  let AssetsFiles = await CDN.List("Assets");

  if (AssetsFiles.Data) {
    for (const File of AssetsFiles.Data) {
      let deleteResult = await CDN.Delete("Assets", File.ObjectName);

      if (deleteResult.Error) {
        console.log("delete", File.ObjectName, "failed");
      }
    }
  } else if (AssetsFiles.Error) {
    console.log(AssetsFiles.Error);
  }
}

ClearMyRemoteAssetsFolder();
```

---
_Source: https://npm.io/package/bunnycdnjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
