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

# Commit and upload

> 新しいアプリケーションを Square Cloud にアップロードするか、既存のアプリケーションに新しいファイルを commit します。

## 新しいアプリケーションのアップロード

`api.applications.create(file)` は zip をアップロードして、まったく新しいアプリケーションを作成します。`file` 引数は、ローカルファイルパスまたは `Buffer` のいずれかです。

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

const api = new SquareCloudAPI(process.env.SQUARE_API_KEY!);

const result = await api.applications.create(join(__dirname, "my-app.zip"));

console.log(result.id);   // 新しく作成されたアプリケーション ID
console.log(result.name); // 表示名
console.log(result.lang); // 言語スラッグ (例: "javascript")
console.log(result.ram);  // 割り当てられた RAM (MB)
```

zip には最低限、以下が含まれている必要があります:

* **メインファイル** — アプリケーションのエントリーポイント
* **依存関係ファイル** — `package.json`、`requirements.txt` など
* **`squarecloud.app`** — 名前、説明、メインファイル、バージョンなどを記載した設定ファイル。[設定ファイルガイド](/ja/getting-started/config-file) を参照してください

## 既存のアプリケーションへのファイルの commit

`app.commit(file, fileName?)` は、すでにデプロイ済みのアプリケーションにファイルをアップロードします。複数のファイルを一度に置き換えるには zip を渡し、1 つのファイルだけを更新するには単一のファイルを渡します。

| Parameter  | Type               | Description                                                     |
| ---------- | ------------------ | --------------------------------------------------------------- |
| `file`     | `string \| Buffer` | ローカルファイルパスまたは `Buffer` の内容                                      |
| `fileName` | `string?`          | アップロードに付与される名前。`.zip` はサーバー側で展開されます。それ以外の拡張子は単一のファイルとして書き込まれます。 |

<Tabs>
  <Tab title="単一のファイルを commit (Buffer)">
    ```typescript theme={null}
    const content = Buffer.from("console.log('hello')\n");
    await app.commit(content, "index.js");
    ```
  </Tab>

  <Tab title="ディスクから zip を commit">
    ```typescript theme={null}
    import { readFile } from "node:fs/promises";

    const zip = await readFile("./dist.zip");
    await app.commit(zip, "dist.zip");
    ```
  </Tab>

  <Tab title="パス指定でファイルを commit">
    ```typescript theme={null}
    import { join } from "node:path";

    const filePath = join(__dirname, "index.js");
    await app.commit(filePath, "index.js");
    ```
  </Tab>
</Tabs>

<Warning>
  v3 では `commit()` は 3 番目の `restart` 引数を受け付けていました。**v4 では 3 番目のパラメータは削除されています**。再起動が必要な場合は、commit の後に `app.restart()` を使用してください。
</Warning>

```typescript theme={null}
await app.commit(zip, "dist.zip");
await app.restart();
```
