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

# Managing applications

> Inspect, control and operate an application through the Application class — status, logs, metrics, lifecycle (start, stop, restart) and deletion.

Every operation on this page starts by obtaining an `Application` instance:

```typescript theme={null}
import { SquareCloudAPI } from "@squarecloud/api";

const api = new SquareCloudAPI(process.env.SQUARE_API_KEY!);
const app = await api.applications.fetch("abc123def456abc123def456");
```

`api.applications.fetch(id)` returns an `Application`. When the app has a website domain bound to it, it is returned as a `WebsiteApplication` — refine the type at runtime with `app.isWebsite()` before using `.network` (see [Network](/en/sdks/js/network)).

## Application properties

| Property      | Type             | Description                                                                                                       |
| ------------- | ---------------- | ----------------------------------------------------------------------------------------------------------------- |
| `id`          | `string`         | Application ID (24 hex chars)                                                                                     |
| `name`        | `string`         | Display name                                                                                                      |
| `description` | `string?`        | Description from `squarecloud.app`                                                                                |
| `url`         | `string`         | Web dashboard URL                                                                                                 |
| `ram`         | `number`         | Allocated RAM in MB                                                                                               |
| `cluster`     | `string`         | Cluster the app runs on                                                                                           |
| `language`    | `string`         | `javascript` \| `typescript` \| `python` \| `java` \| `elixir` \| `rust` \| `go` \| `php` \| `dotnet` \| `static` |
| `domain`      | `string \| null` | Default `<subdomain>.squareweb.app` host (`null` for non-web apps)                                                |
| `custom`      | `string \| null` | Custom domain bound to the app, when configured                                                                   |
| `createdAt`   | `Date`           | Creation date                                                                                                     |

<Note>
  In v4, `app.custom` is `null` when no custom domain is set (was `undefined` in v3).
</Note>

## Getting the application status

`app.getStatus()` returns an `ApplicationStatus` instance with the live runtime state.

```typescript theme={null}
const status = await app.getStatus();

console.log(status.status);          // "running" | "starting" | "restarting" | "exited" | "created" | "deleting"
console.log(status.running);         // boolean
console.log(status.usage.cpu);       // "0.22%"
console.log(status.usage.ram);       // "70MB"
console.log(status.usage.network);   // { total: "0 KB ↑ 0 KB ↓", now: "0 KB ↑ 0 KB ↓" }
console.log(status.usage.storage);   // "0B"
console.log(status.uptime);          // Date | undefined
console.log(status.uptimeTimestamp); // number | undefined
```

### Summary status for every application

To avoid one request per app, call `api.applications.statusAll()`:

```typescript theme={null}
const list = await api.applications.statusAll();

for (const summary of list) {
    console.log(`${summary.applicationId} → running=${summary.running}`);
    if (summary.running) {
        console.log(`  cpu=${summary.usage.cpu}, ram=${summary.usage.ram}`);
    }

    // Promote a summary to the full status with .fetch()
    const full = await summary.fetch();
    console.log(full.uptime);
}
```

## Getting the logs

`app.getLogs()` returns the most recent log output as a `string`.

```typescript theme={null}
const logs = await app.getLogs();
console.log(logs);
```

## Getting metrics

`app.getMetrics()` returns the last 24 hours of CPU, RAM and network samples (up to **288 points**, one every 5 minutes).

```typescript theme={null}
const metrics = await app.getMetrics();

console.log(metrics.length, "data points");
console.log(metrics[0]);
// { timestamp: 1717084800000, cpu: 12.3, ram: 187, network: { ... } }
```

<Warning>
  `getMetrics()` requires the application to have **at least 512MB of RAM** allocated.
</Warning>

## Real-time event stream

`app.realtime()` opens a [Server-Sent Events](https://developer.mozilla.org/docs/Web/API/Server-sent_events) stream. See the dedicated [Realtime](/en/sdks/js/realtime) page for a full example.

## Lifecycle

All lifecycle methods resolve to `boolean` (`true` on success).

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

## Deleting an application

<Warning>
  `app.delete()` permanently removes the application. Unless you have a [snapshot](/en/sdks/js/snapshots), the data **cannot be recovered**.
</Warning>

```typescript theme={null}
const deleted = await app.delete();
console.log(deleted); // true | false
```

## Refreshing the application data

`app.fetch()` refetches the application from the API and returns a brand-new `Application` instance. Use it when you suspect the cached data is stale.

```typescript theme={null}
const fresh = await app.fetch();
```
