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

# Host a Node.js App, API or Bot

> Deploy Node.js and TypeScript apps, APIs and Discord bots on Square Cloud: set MAIN and START, install dependencies from package.json and go live in minutes.

The Node.js runtime runs JavaScript and TypeScript bots, APIs and server-rendered websites. Square Cloud installs your dependencies from `package.json` and starts your app with Node.js.

## Before you begin

* Node.js and npm on your machine. If you don't have them, download them from the [official Node.js website](https://nodejs.org/).
* A Square Cloud account: [sign up](https://squarecloud.app/en/signup) with your email or GitHub.
* An active plan. See the [plans](https://squarecloud.app/en/pricing) and pick the one that fits your project.

## Configure Square Cloud

<Note>
  If you upload your application through the dashboard, you can skip this section: the dashboard creates the `squarecloud.app` configuration file for you.
</Note>

<Card title="Configuration file reference" icon="link" href="/en/getting-started/config-file">
  The `squarecloud.app` file tells Square Cloud how to run your application: its main file, memory, runtime version, name and, for a website, its subdomain.
</Card>

A complete configuration file for each kind of app:

<Tabs>
  <Tab title="Bot or worker">
    ```systemd squarecloud.app theme={"system"}
    MAIN=index.js
    MEMORY=256
    VERSION=recommended
    DISPLAY_NAME=My bot
    ```
  </Tab>

  <Tab title="Website or API">
    ```systemd squarecloud.app theme={"system"}
    MAIN=index.js
    MEMORY=512
    VERSION=recommended
    DISPLAY_NAME=My website
    SUBDOMAIN=mywebsite
    ```
  </Tab>
</Tabs>

`VERSION=recommended` runs the current LTS line of Node.js, and `VERSION=latest` the newest release.

## What Square Cloud runs

<Tabs>
  <Tab title="JavaScript">
    * If the `START` field is not defined in the configuration file, Square Cloud runs `node MAIN`. When the app has 1024 MB of memory or more, it adds `--max_old_space_size=<MEMORY>` (the Node.js heap limit, in MB). If the `START` field is defined, the value in it will be executed directly. For more information about configuration file parameters, visit [configuration parameters](/en/getting-started/config-file#configuration-parameters).
  </Tab>

  <Tab title="TypeScript">
    * If the `START` field is not defined in the configuration file, Square Cloud runs `npx tsx MAIN`, which runs the TypeScript file specified in `MAIN` directly. `tsx` is installed together with your dependencies. If the `START` field is defined, the value in it will be executed directly. For more information about configuration file parameters, visit [configuration parameters](/en/getting-started/config-file#configuration-parameters).
  </Tab>
</Tabs>

* If the app has no `node_modules` folder, Square Cloud runs `npm install --no-audit --no-fund` before starting it. Packages in `devDependencies` are not installed, because the runtime sets `NODE_ENV=production`. When `node_modules` already exists, the install step is skipped.

### Port and host for websites and APIs

Square Cloud sets the `PORT` environment variable to `80` and `HOST` to `0.0.0.0`. Your server must listen on that port and on all network interfaces, for example with Express:

```javascript theme={"system"}
const port = Number(process.env.PORT) || 80;
app.listen(port, '0.0.0.0');
```

Next.js, Nuxt, React Router, Astro and SolidStart read `PORT` by themselves: their [framework guides](#framework-guides) say when there is nothing to change.

## Prepare the project

### Required files

* [`squarecloud.app`](/en/getting-started/config-file), at the root of the ZIP.
* Your main file, for example `index.js` or `src/index.ts`.
* [`package.json`](/en/articles/how-to-create-your-package-json), with your dependencies. An upload without it fails with `INVALID_DEPENDENCY`.

<Warning>The configuration file (`squarecloud.app`) must be located at the root of the zip file. Otherwise, Square Cloud will not be able to find it during deploy.</Warning>

<Note>
  Square Cloud runs TypeScript natively with `tsx` (`npx tsx MAIN`), but compiling to JavaScript is still recommended for production: build it on your machine and point `MAIN` to the compiled file.
</Note>

### What to leave out

* `node_modules`: Square Cloud removes this folder from your upload and installs the dependencies from `package.json` on the first start. That keeps the upload small and builds the dependencies for the server's system.
* Lockfiles (`package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`): the CLI and the VS Code extension leave them out by default, so npm installs the newest versions allowed by the ranges in `package.json`. When you need the exact versions of your lockfile, re-include it with `!package-lock.json` in your [`squarecloud.ignore`](/en/getting-started/squarecloud-ignore).

## Framework guides

<CardGroup cols={3}>
  <Card title="Express" icon="network-wired" href="/en/tutorials/api/express" />

  <Card title="Fastify" icon="cat" href="/en/tutorials/api/fastify" />

  <Card title="NestJS" icon="wifi" href="/en/tutorials/api/nestjs" />

  <Card title="Next.js" icon="n" href="/en/tutorials/website/nextjs" />

  <Card title="Nuxt" icon="mountains" href="/en/tutorials/website/nuxt" />

  <Card title="React Router" icon="bolt" href="/en/tutorials/website/remix" />

  <Card title="Angular" icon="angular" href="/en/tutorials/website/angular" />

  <Card title="Astro" icon="rocket-vertical" href="/en/tutorials/website/astrojs" />

  <Card title="SolidJS" icon="s" href="/en/tutorials/website/solidjs" />

  <Card title="Qwik" icon="circle-bolt" href="/en/tutorials/website/qwik" />

  <Card title="React" icon="react" href="/en/tutorials/website/react" />

  <Card title="Vue" icon="vuejs" href="/en/tutorials/website/vue" />
</CardGroup>

Single-page apps built with Vite, React, Vue or Preact can also run without Node.js, on the [static runtime](/en/articles/getting-started-with-html).

## Troubleshooting

<AccordionGroup>
  <Accordion title="The main file is invalid or corrupted" icon="file" iconType="solid">
    This error occurs when the file defined as "main" for your application in the
    configuration file does not exist, is written incorrectly, or the path
    is wrong. If your main file is inside a folder, for
    example, you must specify `folder/file.js`.
  </Accordion>

  <Accordion title="Insufficient memory" icon="memory" iconType="solid">
    The minimum amount of RAM required to host a bot is 256MB and for
    a site/API is 512MB. However, depending on the size and complexity of
    your application, it may be advisable to allocate a larger amount of RAM to
    avoid your application running out of memory and crashing.
  </Accordion>
</AccordionGroup>

For other problems, see [Troubleshooting](/en/platform/troubleshooting).

## Deploy

### Via dashboard

<Steps>
  <Step title="Access the Upload Page">
    Access the [upload page](https://squarecloud.app/en/dashboard/new) and upload your project zip file.
  </Step>

  <Step title="Configure Your Environment">
    After uploading your zip, you will need to configure the name, main file or runtime environment and other settings for your project.\
    If you are uploading a web project, make sure to select "Web Publication" and set a subdomain to your project.
  </Step>

  <Step title="Deploy Your Project">
    Finally, click on the "Deploy" button to host your project on Square Cloud.\
    After deployment, you can monitor your project's status and logs from the dashboard.

    <Frame>
      <img src="https://cdn.squarecloud.app/docs/articles/dashboard/uploading.gif" alt="Uploading application to Square Cloud" style={{ borderRadius: "0.2rem" }} />
    </Frame>
  </Step>

  <Step title="Confirm Your App Is Live">
    Your first deploy usually takes less than a minute. In the [dashboard](https://squarecloud.app/en/dashboard), wait for your application status to show as running and check the logs for any startup errors.\
    If you deployed a website or API, open `https://<your-subdomain>.squareweb.app` in your browser: you should see your application responding. If you deployed a bot, send it a command to confirm it is online.
    <Tip>App not starting? See the [Troubleshooting guide](/en/platform/troubleshooting/app-wont-start) for the most common causes and fixes.</Tip>
  </Step>
</Steps>

### Via CLI

To use this method, your project needs a configuration file named `squarecloud.app` at its root. It tells Square Cloud how to run your application.

<Card title="Configuration file guide" icon="link" href="/en/getting-started/config-file">
  Learn how to create the `squarecloud.app` configuration file that defines your application's environment.
</Card>

<Steps>
  <Step title="Install the CLI">
    Install the [Square Cloud CLI](/en/cli-reference/installation). If you already have it, run the same command to update it:

    <CodeGroup>
      ```bash macOS, Linux, and WSL theme={"system"}
      curl -fsSL https://cli.squarecloud.app/install | bash
      ```

      ```bash Windows with npm theme={"system"}
      npm install -g @squarecloud/cli@latest
      ```
    </CodeGroup>
  </Step>

  <Step title="Log In">
    Run the command below. It opens your browser: approve the login there and the CLI is ready. There is no API key to copy. For scripts and CI, see [CLI authentication](/en/cli-reference/authentication).

    ```bash theme={"system"}
    squarecloud auth login
    ```
  </Step>

  <Step title="Upload Your Project">
    From your project folder, run the command below. The CLI zips the current folder, leaving out what [`squarecloud.ignore`](/en/getting-started/squarecloud-ignore) lists, and uploads it:

    ```bash theme={"system"}
    squarecloud upload
    ```

    To upload a zip you created yourself, pass it with `--file`:

    ```bash theme={"system"}
    squarecloud upload --file <path/to/zip>
    ```
  </Step>

  <Step title="Confirm Your App Is Live">
    Your first deploy usually takes less than a minute. Check your application status and logs directly from the terminal:

    ```bash theme={"system"}
    squarecloud app status
    squarecloud app logs
    ```

    If you deployed a website or API, open `https://<your-subdomain>.squareweb.app` in your browser: you should see your application responding. If you deployed a bot, send it a command to confirm it is online.
    <Tip>App not starting? See the [Troubleshooting guide](/en/platform/troubleshooting/app-wont-start) for the most common causes and fixes.</Tip>
  </Step>
</Steps>

## Next steps

<CardGroup cols={3}>
  <Card title="Environment variables" icon="key" href="/en/platform/environment-variables">
    Keep secrets and settings out of your code and read them at runtime.
  </Card>

  <Card title="Custom domain" icon="globe" href="https://help.squarecloud.app/en-us/article/how-to-set-up-your-own-domain-cnamedns-1fzbrgh/">
    Serve your app on your own domain, on the Standard plan and above.
  </Card>

  <Card title="Troubleshooting" icon="wrench" href="/en/platform/troubleshooting">
    Fix an app that does not start or a site that does not respond.
  </Card>
</CardGroup>

## Contact us

If you continue facing **technical difficulties**, our **specialized support team** is available to assist you. [**Contact us**](https://squarecloud.app/en/support) and we'll be happy to help you resolve any issue: support quality is a big part of why developers rate Square Cloud [**4.9/5 across 402 reviews**](https://www.trustpilot.com/review/squarecloud.app) on Google and Trustpilot.


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