Introduction

  • Before you begin, make sure you have Node.js and npm installed on your system. If you don’t have them yet, you can download them from the official Node.js website.
  • Next, you will need to create an account on Square Cloud, which can be done through the sign up page. You can use your email to create an account.
  • Finally, you need to have an active paid plan on your account. You can view our plans and purchase one according to your needs here.

Setting up NestJS CLI

To use the NestJS command-line interface (CLI), you need to install it globally on your system. Run the following command:

npm install -g @nestjs/cli

This command installs the @nestjs/cli package globally on your system, which allows you to use the nest command from anywhere in your terminal.

Creating a NestJS Project

To create a new NestJS project, run the following command:

nest new my-app

In this command, nest new my-app is used to create a new NestJS project. The nest new command is a tool that comes with nest, the NestJS CLI (Command Line Interface). It is used to initialize a new NestJS application.

my-app is the name of the new application. This command creates a new directory named my-app and sets up the necessary files and dependencies for a basic NestJS application.

Configuring Port 80

After generating the NestJS project with the command nest new my-app, the file you need to modify to change the port is main.ts. This file is located at the root of your project directory, inside the src folder.

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(80); // Change the port number here to 80
}
bootstrap();

Port 80 is the default port for HTTP traffic.

Building the Application

NestJS uses TypeScript, so you could compile your TypeScript code to JavaScript before you can run your application.

You can build your application by running the following command:

npm run build

This command runs the build script defined in your package.json file, which in turn runs the nest build command. This command compiles your TypeScript code to JavaScript.

Creating the squarecloud config file

Learn about: how to make the configuration file for Square Cloud.

The squarecloud.app file is a configuration file that will be used to configure your application; it will be used to define the name, description, version, main file, among other things.

Configuring the MAIN field

You need to specify the main file of your application in the MAIN field of squarecloud.app. For a NestJS application, the main file is the compiled JavaScript file of your main.ts file, which is dist/main.js.

Here’s how you can set it:

squarecloud.app
MAIN=dist/main.js

Configuring the START Field

In the Square Cloud configuration file, the START field is optional and is only necessary if you are using a custom script to start the website or API. In the example provided, the START field is not necessary.

Purchasing a Plan Before Uploading Your Project

Before you can upload your project to Square Cloud, it’s important to understand that you need to purchase a plan. The type of plan you choose will depend on the resources required by your application. You can view our plans here.

Are you wondering how much RAM and CPU your plan needs to host a NestJS application? Don’t worry, we’re here to help. NestJS is a progressive Node.js framework for building efficient and scalable server-side applications. It’s modular, testable, and strongly typed with TypeScript, making it a great choice for complex back-end development. Our Standard plan offers 4GB of RAM and 4vCPU, which should be sufficient for most Nestjs applications. However, if you’re working on a larger project or need more stability, we recommend considering our Pro plan. With additional resources, you can ensure smooth performance even under high demand. To purchase, simply click here.

Uploading Project to Square Cloud

After preparing your project files, you can now upload them to Square Cloud and host your project.

Access the Square Cloud Dashboard and upload your project files.

Troubleshooting

Additional Resources

For more information about Nestjs and its tools, visit the official Nestjs documentation. There, you’ll find detailed guides, tutorials, and API documentation to help you make the most of Nestjs.

If you continue to experience any issues, please don’t hesitate to contact our support team.