---
title: "JavaScript SDK"
description: "Use the AWS S3 SDK with Edge Storage and fetch() for Compute, CDN and DNS, with examples for uploading files and generating presigned share links."
url: "https://edge.network/academy/sdk-javascript"
category: "API & SDKs"
readingTime: "3 min"
level: "intermediate"
---

# 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().

## 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):

```bash
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**):

```js
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

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

### Upload a file

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

### List objects

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

### Download a file

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

### Generate a presigned URL

```js
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:

```js
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](/academy/api-reference) for endpoint details.

## Practical example: upload an image and get a share link

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

```js
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.

## Next steps

- [Python SDK](/academy/sdk-python)
- [Storage documentation](/docs/storage)
