Deploying a TypeScript Express application to Render

Bjorn Krolsavatar

Bjorn Krols

Published on
02 March 2022

In this tutorial you will learn how to deploy a TypeScript Express application as a Render Web Service.

The final code of this article can be found here.

Prerequisites

  • A Render account
  • A GitHub or GitLab account
  • A computer with Node.js and NPM

Creating the application

npm init -y
npm install typescript ts-node @types/node --save-dev
npm install express
npm install @types/express --save-dev

tsconfig.json

{
  "compilerOptions": {
    "esModuleInterop": true,
    "outDir": "./dist"
  }
}

./src/application.ts

import express from "express";

const application = express();

const port = 3000;

application
  .get("/", (req, res) => {
    res.send({
      message: "Hello, World!",
    });
  })
  .get("/random", (req, res) => {
    res.send({
      number: Math.floor(Math.random() * 100),
    });
  });

application.listen(port, () => {
  console.log(`Application listening on port ${port}`);
});

To run the application locally:

npx ts-node ./src/application.ts

Deploying the application

Add the following build and start commands to the scripts section of your package.json:

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

Create a new Web Service on Render, and give Render permission to access your repository.

Configure the following settings:

  • Environment: Node
  • Build Command: npm ci; npm run build
  • Start Command: npm run start

That's all! Don't forget to delete the Web Service once you're done testing.

The final code of this article can be found here.

Subscribe to our newsletter

The latest news, articles, and resources, sent to your inbox weekly.

More like this