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

# How to Host Fastify Applications

> Learn how to create and deploy Fastify applications on Shard Cloud.

## Introduction

This guide covers deploying Fastify applications on Shard Cloud. Fastify is a high-performance web framework for Node.js.

## Creating Your Project

Ensure you have **Node.js** and **npm** installed. Download from [nodejs.org](https://nodejs.org/).

### Installing Fastify

```bash theme={null}
npm init -y
npm install fastify
```

### Basic Fastify Application

Create an `index.js` file:

```javascript index.js theme={null}
import Fastify from "fastify";

const fastify = Fastify({ logger: true });

fastify.get("/", async (request, reply) => {
  return { message: "Hello World!" };
});

fastify
  .listen({ port: 80, host: "0.0.0.0" })
  .then((address) => {
    fastify.log.info(`Server listening at ${address}`);
  })
  .catch((err) => {
    fastify.log.error(err);
    process.exit(1);
  });
```

<Warning>
  Always use `host: '0.0.0.0'` to ensure the server is accessible externally.
</Warning>

### Package.json Configuration

```json package.json theme={null}
{
  "name": "my-fastify-app",
  "version": "1.0.0",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "fastify": "^4.0.0"
  }
}
```

## Shard Cloud Configuration

Create a `.shardcloud` file:

```systemd .shardcloud theme={null}
DISPLAY_NAME=Fastify API
DESCRIPTION=High-performance Fastify API
MAIN=index.js
MEMORY=512
VERSION=recommended
SUBDOMAIN=my-fastify-api
```

## Deploying

<Steps>
  <Step title="Prepare Your Files">
    Ensure you have: - `index.js` - `package.json` - `.shardcloud`
  </Step>

  <Step title="Exclude Unnecessary Files">
    Remove: `node_modules/`, `package-lock.json`
  </Step>

  <Step title="Create ZIP Archive">Compress your project folder.</Step>

  <Step title="Upload to Shard Cloud">
    Go to [Shard Cloud Dashboard](https://shardcloud.app/dash/applications) and
    upload your project.
  </Step>
</Steps>

## Additional Resources

Visit the [official Fastify documentation](https://fastify.dev/) for more information.

## Troubleshooting

<AccordionGroup>
  <Accordion title="Connection refused errors">
    Ensure you're binding to `0.0.0.0` instead of `localhost` or `127.0.0.1`.
  </Accordion>

  <Accordion title="Application crashes on startup">
    Check your logs in the dashboard for detailed error messages.
  </Accordion>
</AccordionGroup>
