Node.js - Deploying Your TypeScript + Fastify App to Render.com



Project setup

Suppose you have a Node.js + TypeScript app like this:

my-app/

├── src/

│   └── index.ts

├── dist/

├── package.json

└── tsconfig.json


In package.json:

"scripts": {
  "build": "tsc",
  "start": "node dist/index.js"
}

tsconfig.json:

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ES2022",
    "moduleResolution": "node",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "rootDir": "src",  
    "outDir": "dist",
  },
  "include": ["src"]
}

Your tsconfig.json compiles src/ into dist/.

Render.com settings summary

Build Command:

npm install && npm run build


Start Command:

npm start

Problem: No open ports detected


After deploying, Render might show:

==> No open ports detected on 0.0.0.0, continuing to scan..

This usually happens because Fastify’s default listen() binds to localhost (127.0.0.1).
Render’s routing layer can’t access your server on that address.

 Fix: bind Fastify to 0.0.0.0
In your src/index.ts (or wherever you start Fastify):

import fastify from 'fastify';

const app = fastify();
const port = process.env.PORT ? parseInt(process.env.PORT) : 3000;

app.get('/', async () => {
  return { message: 'Hello from Fastify!' };
});

app.listen({ port: port, host: '0.0.0.0' }, (err, address) => {
  if (err) throw err;
  console.log(`🚀 Backend running at ${address}`);
});


No comments:

Theme images by merrymoonmary. Powered by Blogger.