> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apexxcloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Node.js SDK

> Documentation for ApexxCloud Node.js SDK

<Note>
  If you want sdk support for languages that is not supported yet, please
  [contact us](support@apexxcloud.com) so we can add it. you can also integrate
  the [api](/api-reference/introduction) directly in your own applications.
</Note>

## Installation

<CodeGroup>
  ```bash npm theme={null}
  npm install @apexxcloud/sdk-node
  ```

  ```bash yarn theme={null}
  yarn add @apexxcloud/sdk-node
  ```
</CodeGroup>

## Initialization

```javascript theme={null}
const ApexxCloud = require("@apexxcloud/sdk-node");

const storage = new ApexxCloud({
  accessKey: process.env.APEXXCLOUD_ACCESS_KEY,
  secretKey: process.env.APEXXCLOUD_SECRET_KEY,
  region: "bucket-region",
  bucket: "bucket-name",
});
```

## File Operations

### Upload a File

```javascript theme={null}
// Simple upload
const result = await storage.files.upload("path/to/file.jpg", fileBuffer, {
  bucketName: "bucket-name", // optional if default bucket set
  visibility: "private", // optional, defaults to 'private'
  contentType: "image/jpeg", // optional, specify mime type
});
```

### Delete a File

```javascript theme={null}
await storage.files.delete("path/to/file.jpg", {
  bucketName: "bucket-name", // optional if default bucket set
});
```

### Get a Signed URL for Download

```javascript theme={null}
const url = await storage.files.getSignedUrl("download", {
  bucketName: "bucket-name", // optional if default bucket set
  key: "path/to/file.jpg",
  expiresIn: 3600, // optional, defaults to 1 hour (in seconds)
});
```

### Generate Pre-Signed URLs for Operations

```javascript theme={null}
// All operations use storage.files.getSignedUrl instead of storage.getSignedUrl
const signedUrl = await storage.files.getSignedUrl("upload", {
  bucketName: "bucket-name", // optional if default bucket set
  key: "path/to/file.jpg",
  expiresIn: 3600, // optional, defaults to 1 hour (in seconds)
});
```

Available operation types:

* `upload`: Create new file
* `delete`: Delete existing file
* `download`: Download file
* `start-multipart`: Initialize multipart upload
* `uploadpart`: Upload individual part
* `completemultipart`: Complete multipart upload
* `cancelmultipart`: Cancel multipart upload

### Purge a File Cache

```javascript theme={null}
const result = await storage.files.purge("path/to/file.jpg", {
  bucketName: "bucket-name", // optional if default bucket set
});
```

This will purge cdn cache for the original file and all the transformations of the file

## Multipart Upload

```javascript theme={null}
// 1. Start the multipart upload
const upload = await storage.files.startMultipartUpload("large-file.zip", {
  bucketName: "bucket-name", // optional if default bucket set
  totalParts: 3, // required
  mimeType: "application/zip", // optional
  visibility: "public", // optional
});

// 2. Upload individual parts
const parts = [];
for (let partNumber = 1; partNumber <= 3; partNumber++) {
  const partResult = await storage.files.uploadPart(
    "large-file.zip",
    filePartBuffer,
    {
      bucketName: "bucket-name", // optional if default bucket set
      uploadId: upload.uploadId,
      partNumber: partNumber,
      totalParts: 3,
    }
  );
  parts.push(partResult);
}

// 3. Complete the multipart upload
await storage.files.completeMultipartUpload("large-file.zip", parts, {
  bucketName: "bucket-name", // optional if default bucket set
  uploadId: upload.uploadId,
});
```

If you need to cancel the upload:

```javascript theme={null}
await storage.files.cancelMultipartUpload("file-key", {
  bucketName: "bucket-name", // optional if default bucket set
});
```

## Bucket Operations

### List Bucket Contents

```javascript theme={null}
const contents = await storage.bucket.listContents({
  bucketName: "bucket-name", // optional if default bucket set
  prefix: "folder/", // optional, filter by prefix
  page: 1, // optional, defaults to 1
  limit: 20, // optional, defaults to 20
});
```

## Error Handling

The SDK uses a consistent error handling pattern:

```javascript theme={null}
try {
  await storage.files.upload("./file.jpg", fileBuffer, {
    bucketName: "bucket-name", // optional if default bucket set
  });
} catch (error) {
  console.error("Upload failed:", error);
}
```
