0.0.7-beta • Published 1 year ago

enkei v0.0.7-beta

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Nest Enkei Core Template REST API

Nest Enkei Core Template is a ready-to-use REST API template for Nest.js.

Installation

To get started, create a new Nest.js app and install the Enkei package using pnpm:

# Create a new Nest.js app
$ nest new new-app

# Install Enkei package
$ pnpm add enkei
$ pnpm enkei deploy

Configure The App

  • Configure Environment

    • Copy the env.example file to .env and set the DATABASE_SYNCHRONIZE environment variable to true.
       # Database
       DATABASE_TYPE=
       DATABASE_HOST=
       DATABASE_PORT=
       DATABASE_NAME=
       DATABASE_USERNAME=
       DATABASE_PASSWORD=
       DATABASE_SECRET_KEY=
       DATABASE_SSL=
       DATABASE_LOGGING=
       DATABASE_SYNCHRONIZE=
    
       #Storage
       S3_END_POINT=
       S3_KEY_ID=
       S3_SECRET_KEY=
       S3_BUCKET_NAME=
    
       # JWT
       JWT_SECRET_KEY=your-secret-key
       JWT_TTL=1h
  • Import Module

    • Import the necessary modules (DatabaseModule, FrontOfficeModule, BackOfficeModule) from the Enkei package into your app.
      import { Module } from '@nestjs/common';
      import { AppController } from './app.controller';
      import { AppService } from './app.service';
      import {DatabaseModule,FrontOfficeModule,BackOfficeModule} from 'enkei';
      @Module({
        imports: [DatabaseModule,FrontOfficeModule,BackOfficeModule],
        controllers: [AppController],
        providers: [AppService],
      })
      export class AppModule {}
  • Configure Swagger
    • Update the main.ts file to configure Swagger documentation. Use the DocumentBuilder to set the API title, description, version, and authentication methods.
      const config = new DocumentBuilder()
        .setTitle('Api Documentation')
        .setDescription('Backend API description')
        .setVersion('1.0')
        .addBearerAuth()
        .addBasicAuth()
        .build();
      const document = SwaggerModule.createDocument(app, config);
      SwaggerModule.setup('api', app, document);

Configure Migration Database

  • Configure package.json add this below
  "scripts":{
    "typeorm": "pnpm build && pnpm dlx typeorm -d node_modules/enkei/dist/database/data-source.js",
    "migration:generate": "pnpm typeorm -- migration:generate",
    "migration:run": "pnpm typeorm -- migration:run",
    "seed:run":"pnpm build && pnpm typeorm-seeding -d node_modules/enkei/dist/database/data-source.js seed {path default seed}"
  }  
  • Script Migration Database
# generate new migration
$ pnpm typeorm migration:generate src/database/migrations/{name}

# run migration
$ pnpm typeorm migration:run

Start The App

# production
$ pnpm build
$ pnpm start

# development
$ pnpm start:dev

Configure Seeder And Factories Database

NOTE: Seeder

# Account BackOffice
$ super@admin.com
$ Password@1