DEV Community

Adrián UB
Adrián UB

Posted on • Originally published at adrianub.dev on

5 2

Como desplegar NestJS en Deta.sh 🚀

Como desplegar NestJS en Deta.sh 🚀

¿Que es Deta.sh?

Deta es una nube gratuita diseñada pensando en la experiencia del desarrollador y del usuario, nos ayuda crear implementaciones de nuestras ideas en la nube más amigable con los desarrolladores, es totalmente gratuita y para siempre.

En esta podemos desplegar aplicaciones hecha con NodeJs y Python, donde nos proveen un Micro por cada aplicación desplegada.

Creación del proyecto NestJS

Para comenzar a crear nuestro clonaremos el starter de NestJS

git clone https://github.com/nestjs/typescript-starter
Enter fullscreen mode Exit fullscreen mode

Instalamos las dependencias y vemos que nuestro proyecto corra sin ningun error.

Configurar proyecto

Primero crearemos nuestro punto de entrada en src/index.ts:

import { NestFactory } from '@nestjs/core';
import { ExpressAdapter } from '@nestjs/platform-express';
import { AppModule } from './app.module';

const createNestServer = async (expressInstance) => {
  const app = await NestFactory.create(
    AppModule,
    new ExpressAdapter(expressInstance),
  );

  return app.init();
};

export default createNestServer;
Enter fullscreen mode Exit fullscreen mode

Crearemos un archivo llamado index.js en el root de nuestra aplicación:

const express = require('express');
const createServer = require('./dist/index').default;

const app = express();
let nest;

app.use(async (req, res) => {
  if (!nest) {
    nest = express();
    await createServer(nest);
  }
  return nest(req, res);
});

module.exports = app;
Enter fullscreen mode Exit fullscreen mode

Desplegar proyecto

Para poder desplegar nuestra aplicación necesitamos correr los siguientes comandos.

Compilar

Escribe el siguiente comando en la terminal para compilar tu proyecto:

yarn build
Enter fullscreen mode Exit fullscreen mode

Iniciar sesión en Deta

Para iniciar sesión en Deta necesitamos correr el siguiente comando:

deta login
Enter fullscreen mode Exit fullscreen mode

Crear un Micro

Creamos un nuevo micro desde una carpeta anterior a nuestro proyecto:

deta new --node nombre-del-proyecto
Enter fullscreen mode Exit fullscreen mode

Deploy 🚀

Y por ultimo desplegamos el proyecto ejecutando el siguiente comando en el root de la aplicación:

deta deploy
Enter fullscreen mode Exit fullscreen mode

Luego puedes visitar la url creada por Deta y sacar provecho

Ejemplo: https://7dug2x.deta.dev/

GitHub logo adrian-ub / nest-deta

Template for blog post https://adrianub.dev/blog/desplegar-nestjs-en-detash

Description

Nest framework TypeScript starter repository.

Installation

$ yarn
Enter fullscreen mode Exit fullscreen mode

Running the app

# development
$ yarn start

# watch mode
$ yarn run start:dev

# production mode
$ yarn run start:prod
Enter fullscreen mode Exit fullscreen mode

Test

# unit tests
$ yarn run test

# e2e tests
$ yarn run test:e2e

# test coverage
$ yarn run test:cov
Enter fullscreen mode Exit fullscreen mode

Build and Deploy

These steps assume you already have added Deta Micros to your Project.

# build
$ yarn build

# deploy
$ deta deploy
Enter fullscreen mode Exit fullscreen mode

License

This Project is MIT licensed.
Please review the License of NestJS which this example is based on.
Based on nestjs/typescript-starter




Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post