Node.js SDK API Reference

Complete API reference for the easyCDN Node.js SDK, including all methods, options, and TypeScript types.

ApiClient

The main client class for interacting with the easyCDN API from Node.js applications.

Client Initialization

tsx
import { createClient } from '@easycdn/server'

const client = createClient({
  secretKey: process.env.EASYCDN_SECRET_KEY
})

Methods

persist()

Persist a temporary asset uploaded from the client-side Dropzone

Signature
typescript
persist(
  input: { tempAssetId: string }
): Promise<{asset: Asset, preview?: Asset}>
Example
typescript
const result = await client.persist({
  tempAssetId: 'temp_abc123'
})

console.log('Persisted asset URL:', result.asset.url)
Returns
Promise<{asset: Asset, preview?: Asset}>

upload()

Upload a file from path, Buffer, or stream with automatic multipart handling

Signature
typescript
upload(
  input: string | Buffer | NodeJS.ReadableStream,
  options?: {
    fileName?: string
    chunkSize?: number
    onProgress?: (progress: { percentage: number }) => void
    contentType?: string
  }
): Promise<{asset: Asset, preview?: Asset}>
Example
typescript
// Upload from file path
const result = await client.upload('./image.jpg')

// Upload from Buffer with options
const buffer = Buffer.from('content')
const result = await client.upload(buffer, {
  fileName: 'data.txt',
  chunkSize: 5 * 1024 * 1024, // 5MB chunks
  onProgress: ({ percentage }) => {
    console.log(`Progress: ${percentage}%`)
  }
})
  
// Upload from stream
import { createReadStream } from 'fs'
const stream = createReadStream('./video.mp4')
const result = await client.upload(stream, { fileName: 'video.mp4' })
Returns
Promise<{asset: Asset, preview?: Asset}>

healthCheck()

Check the health and connectivity of the easyCDN service

Signature
typescript
healthCheck(): Promise<{status: string, date: string}>
Example
typescript
// Simple health check
const health = await client.healthCheck()

console.log('Status:', health)
Returns
Promise<{status: string, date: string}>

Asset

Represents an uploaded asset in the easyCDN system with all its metadata and properties.

PropertyTypeDescription
url*stringPublic CDN URL for accessing the asset
_id*stringUnique identifier for the asset
bucket*stringStorage bucket where the asset is stored
key*stringStorage key/path for the asset
name*stringOriginal filename of the asset
size*numberFile size in bytes
type*stringMIME type of the asset
createdAt*stringISO timestamp when the asset was created
updatedAt*stringISO timestamp when the asset was last updated
projectId*stringID of the project this asset belongs to
expiresAtstring | nullOptional expiration date for the asset
userIdstringID of the user who uploaded the asset