> ## 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 an Express.js application (Node.js)

## 1. Prerequisites

Before deploying your Express application, make sure 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 Square Cloud to route external traffic to your application, your Express server needs to be listening on the correct interfaces and ports.

In your main code file (e.g., `index.js` or `app.js`), configure `app.listen` with the following parameters:

* **Host:** `0.0.0.0` (This allows the server to accept connections from outside the container).
* **Port:** `80` (The default port used by Square Cloud's load balancer).

### Code Example
```javascript
import express from 'express';
const app = express();

const PORT = 80;
const HOST = '0.0.0.0';

app.get('/', (req, res) => {
  res.send('Express server running on Square Cloud!');
});

app.listen(PORT, HOST, () => {
  console.log(`Server running at http://${HOST}:${PORT}`);
});
```

---

## 3. Deploying

When deploying your application through the Square Cloud Dashboard, pay attention to these steps:

1. **Compression:** Create a `.zip` file with your source code and `package.json` (do not include the `node_modules` folder).
2. **Upload:** In the Dashboard, select the file to upload.
3. **Network Configuration:** In the upload menu, it is essential to check the **"Publish to Web"** option.
4. **Subdomain:** Define the name of your free subdomain (e.g., `my-api`). The final address will be `my-api.squareweb.app`.

---

## 4. Custom Domains (Standard+ Plan)

If you have a **Standard plan or higher**, you are not limited to the `.squareweb.app` subdomain.

* You can configure your own domain (e.g., `www.yourcompany.com`) through the **Network** tab in the application settings, as detailed in our DNS guides.
* Square Cloud automatically manages the SSL certificate (HTTPS) for both the free subdomain and your custom domain.

---

## 5. Performance and Security Tips

* **Environment Variables:** Use Square Cloud's ENVs to manage API keys and database secrets, avoiding exposing sensitive data in your code.
* **Access Logs:** Use the dashboard's **Logs** tab to monitor requests and identify potential errors (status 404, 500) in real time.