How to host Fastify applications
1. Prerequisites
Before uploading your Fastify application, verify that you have:
- Square Cloud Account: Create your account via the Registration Page (Email or GitHub).
- Active Plan: A paid plan is required for hosting. Check the pricing here.
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.
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:
- Cleanup and Compression: Create a
.zipfile containing your source code and thepackage.json. Do not include thenode_modulesfolder, as Square Cloud will install the dependencies automatically during the build. - Upload: In the Dashboard, click on upload new application and select your file.
- Web Publishing: In the submission menu, locate and check the "Publish to Web" option.
- 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.
Updated on: 05/26/2026
Thank you!
