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
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
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.
Property | Type | Description |
---|---|---|
url* | string | Public CDN URL for accessing the asset |
_id* | string | Unique identifier for the asset |
bucket* | string | Storage bucket where the asset is stored |
key* | string | Storage key/path for the asset |
name* | string | Original filename of the asset |
size* | number | File size in bytes |
type* | string | MIME type of the asset |
createdAt* | string | ISO timestamp when the asset was created |
updatedAt* | string | ISO timestamp when the asset was last updated |
projectId* | string | ID of the project this asset belongs to |
expiresAt | string | null | Optional expiration date for the asset |
userId | string | ID of the user who uploaded the asset |