Skip to main content

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.

Installing Fastify

npm init -y
npm install fastify

Basic Fastify Application

Create an index.js file:
index.js
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);
  });
Always use host: '0.0.0.0' to ensure the server is accessible externally.

Package.json Configuration

package.json
{
  "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:
.shardcloud
DISPLAY_NAME=Fastify API
DESCRIPTION=High-performance Fastify API
MAIN=index.js
MEMORY=512
VERSION=recommended
SUBDOMAIN=my-fastify-api

Deploying

1

Prepare Your Files

Ensure you have: - index.js - package.json - .shardcloud
2

Exclude Unnecessary Files

Remove: node_modules/, package-lock.json
3

Create ZIP Archive

Compress your project folder.
4

Upload to Shard Cloud

Go to Shard Cloud Dashboard and upload your project.

Additional Resources

Visit the official Fastify documentation for more information.

Troubleshooting

Ensure you’re binding to 0.0.0.0 instead of localhost or 127.0.0.1.
Check your logs in the dashboard for detailed error messages.