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

# Application

> Reference of the Application class returned by getApplication and createApplication.

`Application` is a small helper that binds an application to the client, so you do not have to repeat its ID. You get one from [`getApplication`](https://docs.camposcloud.com/sdk/javascript/client#getapplication) or [`createApplication`](https://docs.camposcloud.com/sdk/javascript/client#createapplication).

```typescript theme={null}
const app = await api.getApplication({ appId: "YOUR_APP_ID" });

console.log(app.data.name);
await app.restart();
```

The class is also exported by the package (`import { Application } from "@camposcloud/sdk"` in TypeScript), mainly to be used as a type.

## data

```typescript theme={null}
readonly data: ApplicationResponseData
```

The application exactly as the API returned it when the instance was created. See [`ApplicationResponseData`](https://docs.camposcloud.com/sdk/javascript/types#applicationresponsedata).

```typescript theme={null}
const app = await api.getApplication({ appId: "YOUR_APP_ID" });

console.log(app.data._id);
console.log(app.data.allocatedMemoryMB);
console.log(app.data.currentResourceMetrics?.online);
```

> [!WARNING]
>
> `data` is a snapshot. It is **not** refreshed by `start()`, `stop()`, `restart()` or `update()`. Use the value returned by those methods, or call `getApplication` again, to read the current state.

## Methods

Every method calls the matching method of the [client](https://docs.camposcloud.com/sdk/javascript/client.md) with `appId` set to `data._id`, so the same behaviour, errors and limits apply.

| Method | Calls | Returns |
| - | - | - |
| `start()` | [`startApplication`](https://docs.camposcloud.com/sdk/javascript/client#startapplication) | `Promise<ApplicationResponseData>` |
| `stop()` | [`stopApplication`](https://docs.camposcloud.com/sdk/javascript/client#stopapplication) | `Promise<ApplicationResponseData>` |
| `restart()` | [`restartApplication`](https://docs.camposcloud.com/sdk/javascript/client#restartapplication) | `Promise<ApplicationResponseData>` |
| `delete()` | [`deleteApplication`](https://docs.camposcloud.com/sdk/javascript/client#deleteapplication) | `Promise<AxiosResponse>` |
| `update(data)` | [`updateApplication`](https://docs.camposcloud.com/sdk/javascript/client#updateapplication) | `Promise<ApplicationResponseData>` |
| `uploadFile({ file, path })` | [`uploadFile`](https://docs.camposcloud.com/sdk/javascript/client#uploadfile) | `Promise<{ message: string } \| AxiosError>` |
| `downloadFile({ path })` | [`downloadFile`](https://docs.camposcloud.com/sdk/javascript/client#downloadfile) | `Promise<Buffer>` |

### start

```typescript theme={null}
start(): Promise<ApplicationResponseData>
```

```typescript theme={null}
const state = await app.start();
console.log(state.currentResourceMetrics.online);
```

Throws when the application is already running (the API answers with `500`).

### stop

```typescript theme={null}
stop(): Promise<ApplicationResponseData>
```

```typescript theme={null}
await app.stop();
```

Throws when the application is already stopped (the API answers with `500`).

### restart

```typescript theme={null}
restart(): Promise<ApplicationResponseData>
```

```typescript theme={null}
await app.restart();
```

Throws when the application is not running and has no pending settings (the API answers with `500`).

### delete

```typescript theme={null}
delete(): Promise<AxiosResponse>
```

```typescript theme={null}
const response = await app.delete();
console.log(response.data.message);
```

Deletes the application. This cannot be undone, and the instance must not be used afterwards.

### update

```typescript theme={null}
update(data: Omit<UpdateApplicationDataParams, "appId">): Promise<ApplicationResponseData>
```

Takes the same fields as [`updateApplication`](https://docs.camposcloud.com/sdk/javascript/client#updateapplication), without `appId`. `appName`, `memoryMB` and `runtimeEnvironment` are always required.

```typescript theme={null}
const updated = await app.update({
    appName: app.data.name,
    memoryMB: 512,
    runtimeEnvironment: "nodejs",
    startupCommand: app.data.startupCommand,
});

if (updated.restartRequired) {
    await app.restart();
}
```

### uploadFile

```typescript theme={null}
uploadFile({ file, path }: { file: Buffer; path?: string }): Promise<{ message: string } | AxiosError>
```

```typescript theme={null}
import fs from "fs";

const zip = await fs.promises.readFile("./update.zip");
await app.uploadFile({ file: zip, path: "/" });
```

> [!WARNING]
>
> The method takes **one object**, not two positional arguments: `app.uploadFile(zip, "/")` does not work. `file` must be a zip, and `path` must always be passed, otherwise the zip is extracted into a folder called `undefined`. See [`uploadFile`](https://docs.camposcloud.com/sdk/javascript/client#uploadfile).

### downloadFile

```typescript theme={null}
downloadFile({ path }?: { path?: string }): Promise<Buffer>
```

```typescript theme={null}
import fs from "fs";

const everything = await app.downloadFile();
await fs.promises.writeFile("./backup.zip", everything);

const onlySrc = await app.downloadFile({ path: "/src" });
await fs.promises.writeFile("./src.zip", onlySrc);
```

The argument is optional. The result is always a zip archive.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.