Skip to main content

Fix failed Fastify deploy on Render

To get a boilerplate Fastify app to deploy on Render.com, you need to read to listen on PORT environment variable.

Background: When trying to deploy a basic Fastify app to Render.com, I received a generic failure method: Deploy failed for COMMIT_HASH. The log indicated that the server started correctly, and there was no information indicating why the deploy failed.

The fix: I couldn’t find docs for running Fastify on Render.com, but there are example repos for other languages and libraries. The Render example for Express included a reference to process.env.PORT. By adding that to my Fastify app, I was able to successfully deploy.

Copy and paste:

const port = process.env.PORT || 8080;

const server = fastify()

server.listen({ port }, () => "Hello world!");

If you’re using TypeScript, you will have to convert the environment variable to a number:

// TypeScript
const port = process.env.PORT ? parseInt(process.env.PORT) : 8080;

Read more: