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
A Platinum plan or higher is required to host websites or APIs.
A subdomain must be created before deployment.
Port 8080 is mandatory β applications must listen on this port.
π§± 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:
π§ TypeScript Configuration β tsconfig.build.json
tsconfig.build.jsonEnsure your tsconfig.build.json (or tsconfig.json) is set to output to the dist folder. Here's a typical configuration:
It is important that compilerOptions.outDir is set to "dist", as Discloud will look for your compiled app there.
π Main entry point β src/main.ts
src/main.tsEnsure your src/main.ts listens on port 8080 and accepts the port from environment variables. Here's a typical setup:
Important
Port 8080 is mandatory. Even if you set
PORTin your.envfile, it must be8080.Bind to
0.0.0.0(notlocalhost) so external traffic can reach your app.
π¦ package.json β recommended scripts
package.json β recommended scriptsInside your package.json, ensure the build and start scripts are correctly defined:
βοΈ discloud.config β example
discloud.config β exampleHere'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.configMake sure to adjust the ID field to match your registered subdomain from the Discloud dashboard.
π§ͺ Testing locally (production build)
Before uploading to Discloud, verify your app builds and runs correctly:
Build the project locally:
This generates the dist folder with compiled JavaScript.
Test the production build:
Check that the server starts and responds to requests (e.g., via curl http://localhost:8080).
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:
ποΈ Recommended final project structure
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 buildand fix any errors before uploading.Check that all dependencies are listed in
package.json.
Errors when starting (START)
Verify that the
startscript is correct.Follow the Discloud logs to see the exact error message.
Last updated