> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.squarecloud.app/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# How to host a Fastify application (Node.js)

Already have **Fastify installed** (`npm i fastify`) and want to **put your Fastify API online**? This guide shows how to host a Fastify application on Square Cloud — setting `host` to `0.0.0.0` and the right port to run 24/7.

## 1. Prerequisites

Before uploading your Fastify application, verify that you have:
* **Square Cloud Account:** Create your account via the [Registration Page](https://squarecloud.app/en/signup) (Email or GitHub).
* **Active Plan:** A paid plan is required for hosting. Check the [pricing here](https://squarecloud.app/en/pricing).

---

## 2. Technical Web Server Configuration

For your Fastify application to receive external requests on Square Cloud, you must configure the server to listen on port **80** and, crucially, on the **0.0.0.0** network interface.

### Code Example (Fastify v4+)
Unlike other frameworks, Fastify requires the `host` to be explicitly specified to accept external connections in container/cloud environments.

```javascript
const fastify = require('fastify')({ logger: true });

const start = async () => {
  try {
    // Vital configuration for Square Cloud
    await fastify.listen({ 
      port: 80, 
      host: '0.0.0.0' 
    });
    
    console.log("Fastify web server online on port 80");
  } catch (err) {
    fastify.log.error(err);
    process.exit(1);
  }
};

fastify.get('/', async (request, reply) => {
  return { status: 'online', framework: 'Fastify' };
});

start();
```

---

## 3. Deployment Process

Follow these steps to get your application online:

1.  **Cleanup and Compression:** Create a `.zip` file containing your source code and the `package.json`. **Do not include the&#32;`node_modules`&#32;folder**, as Square Cloud will install the dependencies automatically during the build.
2.  **Upload:** In the Dashboard, click on upload new application and select your file.
3.  **Web Publishing:** In the submission menu, locate and check the **"Publish to Web"** option.
4.  **Subdomain Definition:** Choose a name for your free subdomain. The final link will follow the pattern `yoursubdomain.squareweb.app`.

---

## 4. Custom Domains (Standard+ Plan)

If you use the **Standard plan or higher**, you can level up your project by using your own domain (e.g., `api.yoursite.com`).

* The configuration is done in the application's **Network** tab in the Dashboard.
* The SSL certificate (HTTPS) is automatically generated and renewed by Square Cloud, ensuring full security with no additional costs or manual certificate configurations.

---

## 5. Optimization Tips

* **Logger in Production:** Fastify has a built-in logger (Pino). In production, make sure to configure the log level appropriately so as not to overload the log storage unnecessarily.
* **Environment Variables:** Store API keys and database connections in Square Cloud's **ENV** system.
* **Schema Validation:** Take advantage of Fastify's JSON Schema validation system to increase data serialization performance in your hosted API.