> ## Documentation Index
> Fetch the complete documentation index at: https://docs.valyent.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# NestJS

> Learn how to deploy a NestJS application to Valyent

## Introduction

[NestJS](https://nestjs.com) is a progressive Node.js framework for building efficient, reliable and scalable server-side applications. In this article, we are going to deploy a freshly created NestJS API to Valyent.

## Prerequisites

* a UNIX-like system (see [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) if you are using Windows), in order to use the [Valyent CLI](https://docs.valyent.cloud/cli)
* a Valyent account, with a registered payment method (you can sign up [here](https://console.valyent.cloud/auth/sign-up))
* [NodeJS](https://nodejs.org) and [NPM](https://www.npmjs.com) installed on your machine

## Installing the CLI

```bash theme={"system"}
curl -L https://cli.valyent.cloud | sh
```

You can inspect the installation script [here](https://cli.valyent.cloud) and the [GitHub repository](https://github.com/valyentdev/cli).

## Authenticating

```bash theme={"system"}
valyent auth login
```

## 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 :

```bash theme={"system"}
npm i -g @nestjs/cli
```

Then, we can scaffold the NestJS project :

```bash theme={"system"}
nest new <some_project_name> && cd <some_project_name>
```

Now, we can initialize the `valyent.toml` configuration file, that allows to link the local codebase, to a Valyent application :

```bash theme={"system"}
valyent init
```

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

## Adding the Dockerfile

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

```bash theme={"system"}
touch Dockerfile
```

We can fill it this way :

```bash theme={"system"}
FROM node:20

WORKDIR /app

COPY package*.json ./

RUN npm ci

COPY . .

RUN npm run build

CMD [ "node", "dist/main.js" ]
```

## Deploy the project

To expose the application’s port, we need to set up a gateway (in this case, the port 3000):

```bash theme={"system"}
valyent gateways create
```

Then, we can deploy the application :

```bash theme={"system"}
valyent deploy
```

Then, you can type the following:

```bash theme={"system"}
valyent open
```

to see your NestJS application in your browser.
