Articles on: Websites & APIs

How to host NestJS applications

How to Host NestJS Applications on Square Cloud


Hosting a NestJS application on Square Cloud is a straightforward process focused on efficiency. Since NestJS uses TypeScript, the secret to a successful deployment lies in compilation (build) and correctly adjusting the listening port.



1. Adjusting the Port (Port 80)


Square Cloud uses port 80 to route your application's traffic. By default, NestJS usually starts on port 3000. You must change the main.ts file to listen on the correct port.


In your src/main.ts file:

async function bootstrap() {
const app = await NestFactory.create(AppModule);
// Change from 3000 to 80
await app.listen(80);
}
bootstrap();



2. Generating the Build


We do not send the src folder to hosting, as Nest compiles the code into optimized JS.


Run the build command on your local machine:

npm run build

This will generate a folder named dist at the root of your project. This is the content that will be executed on Square Cloud.



3. Preparing the Deployment Package


For an optimized deployment, you must create a .zip file containing the following items:


  • The dist/ folder: (Contains your compiled code).
  • The package.json file: (Required to install production dependencies).
  • The package-lock.json or yarn.lock file: (Ensures the exact versions of the libraries).


Important: Do not include the node_modules folder. Square Cloud will automatically install the dependencies on the server after upload.



4. Configuring the Main File (Main)


When deploying (either via the dashboard or a configuration file), you must point to the entry file inside the compiled folder.


  • Main File: dist/main.js


If you are using the squarecloud.app or squarecloud.config file, the line will look like this:

MAIN=dist/main.js



5. Pro Tips for NestJS


  • Production: Make sure your database dependencies and secrets (like API keys) are configured in the Environment Variables (ENVs) on the Square dashboard, rather than being "hardcoded" into the code.
  • Prisma/TypeORM: If you use an ORM, remember to run migrations or generate the database client during your build process or via postinstall scripts in your package.json.
  • Memory: NestJS applications can consume a bit more RAM during initialization due to dependency injection. Monitor the logs to ensure your plan has sufficient resources.

Updated on: 05/26/2026

Was this article helpful?

Share your feedback

Cancel

Thank you!