Skip to content
Academy
API & SDKs

3 min readintermediate

JavaScript SDK

Edge does not provide its own JavaScript SDK. For Storage, use the standard AWS S3 SDK. For Compute, CDN, and DNS, use the REST API with fetch().

CoversStorageComputeCDNDNS

How it works#

Edge Storage is S3-compatible. Use @aws-sdk/client-s3 with Edge’s endpoint and credentials. For Compute, CDN, and DNS, call the REST API at https://api.edge.network using fetch() with your API key.

Storage: installing and configuring#

Install the AWS S3 client and presigner (for presigned URLs):

Terminal
npm install @aws-sdk/client-s3 @aws-sdk/s3-request-presigner

Configure the client with Edge’s Storage endpoint and your access credentials (found in Console → Storage → Access Keys):

JavaScript
import { S3Client, CreateBucketCommand, PutObjectCommand, GetObjectCommand, ListObjectsV2Command } from '@aws-sdk/client-s3'
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'

const s3 = new S3Client({
  region: 'us-east-1',
  endpoint: 'https://storage.edge.network',
  forcePathStyle: true,
  credentials: {
    accessKeyId: process.env.EDGE_ACCESS_KEY,
    secretAccessKey: process.env.EDGE_SECRET_KEY
  }
})

Set forcePathStyle: true. Edge Storage requires path-style access (for example, storage.edge.network/bucket/key).

Storage operations#

Create a bucket#

JavaScript
await s3.send(new CreateBucketCommand({ Bucket: 'my-bucket' }))

Upload a file#

JavaScript
await s3.send(new PutObjectCommand({
  Bucket: 'my-bucket',
  Key: 'uploads/image.jpg',
  Body: fileBuffer,
  ContentType: 'image/jpeg'
}))

List objects#

JavaScript
const { Contents } = await s3.send(new ListObjectsV2Command({
  Bucket: 'my-bucket',
  Prefix: 'uploads/'
}))

Download a file#

JavaScript
const { Body } = await s3.send(new GetObjectCommand({
  Bucket: 'my-bucket',
  Key: 'uploads/image.jpg'
}))
const data = await Body.transformToByteArray()

Generate a presigned URL#

JavaScript
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'
const url = await getSignedUrl(s3, new GetObjectCommand({
  Bucket: 'my-bucket',
  Key: 'uploads/image.jpg'
}), { expiresIn: 3600 })

Compute, CDN, DNS: REST API with fetch#

For non-Storage products, use fetch() against the Edge API:

JavaScript
const response = await fetch('https://api.edge.network/api/compute/vms', {
  headers: {
    'Authorization': `Bearer ${process.env.EDGE_API_KEY}`,
    'Content-Type': 'application/json'
  }
})
const { data } = await response.json()

Use the same pattern for CDN deployments, DNS zones and records, and VM power operations. See the API reference for endpoint details.

Here’s a complete example that uploads an image and returns a presigned share link:

JavaScript
async function uploadAndShare(buffer, filename) {
  const key = `uploads/${Date.now()}-${filename}`

  await s3.send(new PutObjectCommand({
    Bucket: 'my-bucket',
    Key: key,
    Body: buffer,
    ContentType: 'image/jpeg'
  }))

  const shareUrl = await getSignedUrl(s3, new GetObjectCommand({
    Bucket: 'my-bucket',
    Key: key
  }), { expiresIn: 86400 }) // 24 hours

  return shareUrl
}

Call this from an API route or serverless function. The returned URL can be shared with users. They can view or download the file without authenticating until the URL expires.