NestJS

Practical guide to host NestJS applications on Discloud.

🧭 Introduction

This step-by-step guide shows how to prepare, configure, and deploy a NestJS application on Discloud.

The process involves building your TypeScript code into the dist folder and running the compiled JavaScript on port 8080. NestJS apps are straightforward to deploy because the framework handles routing, dependency injection, and module organization automatically.


πŸ“‹ Requirements


🧱 Local prerequisites

Before continuing, you will need:

  • Node.js installed on your machine.

  • A NestJS project created (e.g. nest new my-app).

  • A Discloud account with a configured subdomain.

  • Optionally: Git, VSCode, and/or the Discloud CLI to make the workflow easier.

If you are not yet familiar with the local environment, check:

NodeJS

🧹 Preparing project files

Before compressing your project into a .zip, create a .discloudignore file in the project root to exclude unnecessary files and folders from the upload:

The .discloudignore file works similarly to .gitignore, but it is used by Discloud to ignore files at upload time.


πŸ”§ TypeScript Configuration – tsconfig.build.json

Ensure your tsconfig.build.json (or tsconfig.json) is set to output to the dist folder. Here's a typical configuration:


πŸš€ Main entry point – src/main.ts

Ensure your src/main.ts listens on port 8080 and accepts the port from environment variables. Here's a typical setup:

Important


Inside your package.json, ensure the build and start scripts are correctly defined:

  • build – compiles TypeScript to dist via the Nest CLI.

  • start – runs the compiled app from the dist folder.

  • start:dev – runs in watch mode locally (not needed for Discloud).


βš™οΈ discloud.config – example

Here's a typical configuration for a NestJS app:

For detailed information about each configuration parameter and all available options, refer to the complete guide:

discloud.config

πŸ§ͺ Testing locally (production build)

Before uploading to Discloud, verify your app builds and runs correctly:

1

Build the project locally:

This generates the dist folder with compiled JavaScript.

2

Test the production build:

Check that the server starts and responds to requests (e.g., via curl http://localhost:8080).

3

Stop the server and proceed to deployment.


πŸ” Environment variables

In NestJS, environment variables are typically accessed via process.env:

  • Common patterns include DATABASE_URL, API_KEY, REDIS_URL, etc.

Example in a service:

For better type safety and validation, consider using the @nestjs/config package to manage environment variables.


A typical NestJS project structure for Discloud might look like:


πŸš€ Deploying to Discloud

You can deploy your NestJS app using any of the supported methods.

DashboardDiscord BotVisual Studio CodeCLI

πŸ› οΈ Troubleshooting (common errors)

App does not open / wrong port

Check if NestJS is listening on port 8080 (process.env.PORT || 8080 in main.ts).

Plan / permission error

Confirm that your account has the correct plan for websites/APIs.

Subdomain not configured

Make sure you followed the subdomain guide before deploying.

Build errors

  • Run locally: npm run build and fix any errors before uploading.

  • Check that all dependencies are listed in package.json.

Errors when starting (START)

  • Verify that the start script is correct.

  • Follow the Discloud logs to see the exact error message.

Last updated