All Projects β†’ kpfromer β†’ Nestjs Typegoose

kpfromer / Nestjs Typegoose

Licence: mit
Typegoose with NestJS

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Nestjs Typegoose

nest-rest-mongo-boilerplate
🍱 backend with nest (typescript), mongoose, and authentication
Stars: ✭ 180 (-16.28%)
Mutual labels:  mongoose, nest, nestjs
Nest User Auth
A starter build for a back end which implements managing users with MongoDB, Mongoose, NestJS, Passport-JWT, and GraphQL.
Stars: ✭ 145 (-32.56%)
Mutual labels:  mongoose, nestjs, nest
Mongoose
Mongoose module for Nest framework (node.js) 🍸
Stars: ✭ 191 (-11.16%)
Mutual labels:  mongoose, nestjs, nest
angular-chat
Angular v.9, Node.js, Nest.js v.6, Mongoose, Socket.io, Passport, Angular Universal SSR (in progress...)
Stars: ✭ 35 (-83.72%)
Mutual labels:  mongoose, nest, nestjs
server-next
😎 The next generation of RESTful API service and more for Mix Space, powered by @nestjs.
Stars: ✭ 43 (-80%)
Mutual labels:  mongoose, nest, nestjs
Nest Angular
NestJS, Angular 6, Server Side Rendering (Angular Universal), GraphQL, JWT (JSON Web Tokens) and Facebook/Twitter/Google Authentication, Mongoose, MongoDB, Webpack, TypeScript
Stars: ✭ 307 (+42.79%)
Mutual labels:  mongoose, nestjs, nest
Nodepress
😎 RESTful API service for Blog/CMS, powered by @nestjs
Stars: ✭ 829 (+285.58%)
Mutual labels:  mongoose, nestjs, nest
Nest Cnode
CNode 瀾区 Nest η‰ˆζœ¬ https://cnodejs.org/
Stars: ✭ 125 (-41.86%)
Mutual labels:  mongoose, nestjs
Nest Event
Event handling with decorators for NestJS Framework
Stars: ✭ 128 (-40.47%)
Mutual labels:  nestjs, nest
Passport
Passport module for Nest framework (node.js) πŸ”‘
Stars: ✭ 211 (-1.86%)
Mutual labels:  nestjs, nest
Serverless Core
Serverless Core module for Nest framework (node.js) 🦊
Stars: ✭ 154 (-28.37%)
Mutual labels:  nestjs, nest
Nest
A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications on top of TypeScript & JavaScript (ES6, ES7, ES8) πŸš€
Stars: ✭ 42,981 (+19891.16%)
Mutual labels:  nestjs, nest
Sequelize
Sequelize module for Nest framework (node.js) 🍈
Stars: ✭ 88 (-59.07%)
Mutual labels:  nestjs, nest
Schedule
Schedule module for Nest framework (node.js) ⏰
Stars: ✭ 137 (-36.28%)
Mutual labels:  nestjs, nest
Simple Todos
A simple web application powered by Nuxt.js πŸ’š & Nest Framework 😻
Stars: ✭ 81 (-62.33%)
Mutual labels:  nestjs, nest
Nestjs Roles
Type safe roles guard and decorator made easy
Stars: ✭ 78 (-63.72%)
Mutual labels:  nestjs, nest
Throttler
A rate limiting module for NestJS to work with Fastify, Express, GQL, Websockets, and RPC 🧭
Stars: ✭ 145 (-32.56%)
Mutual labels:  nestjs, nest
Config
Configuration module for Nest framework (node.js) πŸ“
Stars: ✭ 161 (-25.12%)
Mutual labels:  nestjs, nest
Blog Service
blog service @nestjs
Stars: ✭ 188 (-12.56%)
Mutual labels:  mongoose, nestjs
Elasticsearch
Elasticsearch module based on the official elasticsearch package 🌿
Stars: ✭ 176 (-18.14%)
Mutual labels:  nestjs, nest

nestjs-typegoose

NPM

npm version Build Status Coverage Status npm npm bundle size David

Description

Injects typegoose models for nest components and controllers. Typegoose equivalant for @nestjs/mongoose.

Using Typegoose removes the need for having a Model interface.

Installation

npm install --save nestjs-typegoose

or

yarn add nestjs-typegoose

Documentation

Here is the full documentation describing all basic and advanced features.

Basic usage

You can checkout the example project for more details.

app.module.ts

import { Module } from "@nestjs/common";
import { TypegooseModule } from "nestjs-typegoose";
import { CatsModule } from "./cat.module.ts";

@Module({
  imports: [
    TypegooseModule.forRoot("mongodb://localhost:27017/nest", {
      useNewUrlParser: true,
    }),
    CatsModule,
  ],
})
export class ApplicationModule {}

Create class that describes your schema

cat.model.ts

import { prop } from "@typegoose/typegoose";
import { IsString } from "class-validator";

export class Cat {
  @IsString()
  @prop({ required: true })
  name: string;
}

Inject Cat for CatsModule

cat.module.ts

import { Module } from "@nestjs/common";
import { TypegooseModule } from "nestjs-typegoose";
import { Cat } from "./cat.model";
import { CatsController } from "./cats.controller";
import { CatsService } from "./cats.service";

@Module({
  imports: [TypegooseModule.forFeature([Cat])],
  controllers: [CatsController],
  providers: [CatsService],
})
export class CatsModule {}

Get the cat model in a service

cats.service.ts

import { Injectable } from "@nestjs/common";
import { InjectModel } from "nestjs-typegoose";
import { Cat } from "./cat.model";
import { ReturnModelType } from "@typegoose/typegoose";

@Injectable()
export class CatsService {
  constructor(
    @InjectModel(Cat) private readonly catModel: ReturnModelType<typeof Cat>
  ) {}

  async create(createCatDto: { name: string }): Promise<Cat> {
    const createdCat = new this.catModel(createCatDto);
    return await createdCat.save();
  }

  async findAll(): Promise<Cat[] | null> {
    return await this.catModel.find().exec();
  }
}

Finally, use the service in a controller!

cats.controller.ts

import { Controller, Get, Post, Body } from "@nestjs/common";
import { CatsService } from "./cats.service";
import { Cat } from "./cats.model.ts";

@Controller("cats")
export class CatsController {
  constructor(private readonly catsService: CatsService) {}

  @Get()
  async getCats(): Promise<Cat[] | null> {
    return await this.catsService.findAll();
  }

  @Post()
  async create(@Body() cat: Cat): Promise<Cat> {
    return await this.catsService.create(cat);
  }
}

Requirements

  1. @typegoose/typegoose +6.1.5
  2. @nestjs/common +6.10.1
  3. @nestjs/core +6.10.1
  4. mongoose (with typings @types/mongoose) +5.7.12

License

nestjs-typegoose is MIT licensed.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].