DEV Community

Cover image for Deploy a NestJS API to Software Citadel
Alexis Bouchez
Alexis Bouchez

Posted on

Deploy a NestJS API to Software Citadel

Introduction

Software Citadel is a PaaS that allows you to deploy containerized applications in minutes.

If you want the video version of this post, you can find it here.

Prerequisites

  • a UNIX-like system (see WSL if you are using Windows), in order to use the Software Citadel CLI
  • a Software Citadel account, with a registered payment method (you can sign up here)
  • NodeJS and NPM installed on your computer

Installing the CLI

curl -L https://cli.softwarecitadel.com/install.sh | sh
Enter fullscreen mode Exit fullscreen mode

You can inspect the installation script here and the GitHub repository.

Authenticating

citadel auth login
Enter fullscreen mode Exit fullscreen mode

Initializing the project

In the first place, we are going to set up a new NestJS project. To do that, we’ll need the NestJS CLI, which we can install this this way :

npm i -g @nestjs/cli
Enter fullscreen mode Exit fullscreen mode

Then, we can scaffold the NestJS project :

nest new <some_project_name> && cd <some_project_name>
Enter fullscreen mode Exit fullscreen mode

Now, we can initialize the citadel.toml configuration file, that allows to link the local codebase, to a Software Citadel application :

citadel init
Enter fullscreen mode Exit fullscreen mode

This command will ask you to select/create a project and an associated application.

Adding the Dockerfile

Let’s add a Dockerfile so that Software Citadel can build a Docker image for your application.

touch Dockerfile
Enter fullscreen mode Exit fullscreen mode

We can fill it this way :

FROM node:20

WORKDIR /app

COPY package*.json ./

RUN npm ci

COPY . .

RUN npm run build

CMD [ "node", "dist/main.js" ]
Enter fullscreen mode Exit fullscreen mode

Deploy the project

To expose the application’s port, we need to set up the PORT environment variable :

citadel env set PORT=3000
Enter fullscreen mode Exit fullscreen mode

Then, we can deploy the application :

citadel deploy
Enter fullscreen mode Exit fullscreen mode

Once the deployment is finished, type :

citadel open
Enter fullscreen mode Exit fullscreen mode

to see your NestJS application in your browser.

Top comments (0)