Giter Site home page Giter Site logo

nartc / nest-mean Goto Github PK

View Code? Open in Web Editor NEW
351.0 14.0 83.0 1.23 MB

NestJS Tutorial Repository

TypeScript 85.94% JavaScript 1.65% Dockerfile 0.92% HTML 9.44% CSS 2.05%
nestjs nestjs-typegoose mean-stack nodejs mongoose mongodb expressjs angular typescript

nest-mean's Introduction

NestJS Tutorial Repository

Repository will be separated into server and client directory for NestJS backend and Angular frontend resepctively.

  • Server repository
  • Client repository
  • Docker support
  • Hook up Server and Client

Server-side (NestJS)

This repository houses the Project's backend written using NestJS

  • NSwag: Nswag allows us to generate API Calls to our Backend on our Frontend in forms of Functions. The abstraction of HttpClientModule takes place in the generated file.
  • Steps:
    1. cd ./server & npm i to install all dependencies for Server side
    2. Have an instance of MongoDB running (mongod). If you use an IDE like WebStorm, I have a script called: mongo:local that is going to run mongod subsequently so you can setup a Compound Run Configuration with start:dev and mongo:local to start the Backend with ease.
    3. npm run start:dev to start the server
  • Note: If there's issue connecting to local MongoDB and you make sure that you already have mongod running, go to config/default.ts and check if the MONGO_URI is correct.

Client-side (Angular)

This repository houses the Project's frontend written using Angular 6

  • Ant Design: The components design is by AntDesign (https://ng.ant.design/docs/introduce/en). I really like the subtle looks of AntDesign.
  • Steps: npm i to install all the dependencies then just start the application with ng serve
  • Note: Might be worth it to take a look at proxy.conf.json and how I setup the CLI to use the proxy file when serving so that we can call our backend on localhost:3000. This is so-called Cross Domains Request and our backend does not have CORS setup. Proxy will help us making the requests from 4200 to 3000.

Docker

Docker is supported.

  • Branch: docker
  • Steps: Just clone the repository, check out docker branch then from root directory, run docker-compose up and Docker will take over.
  • Note: Angular application will be served by NGINX on localhost; Nest application will be running on localhost:3000; cAdvisor which monitors our containers will be running on localhost:8080. Again, it's worthwhile to explore the Dockerfile in both client and server directory; also nginx.conf and docker-compose.yml to get the gist of how Docker and Docker Compose work.

P.S: Pull Requests, Contributions are most definitely welcomed :)

nest-mean's People

Contributors

dependabot[bot] avatar nartc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nest-mean's Issues

Suggestion

I don't like the way automapper-ts is used for just a simple transformation on the resulting Object from Mongo. You can use the toObject transform property:
toObject

The automapper-ts project is good but I find that mongoose toObject cover most if not all use cases.

SERVER TODO: Upgrade to current packages/Refactor

Refactor items I found:

  • Swagger. This looks like a simple copy/paste
  • typegoose (unmaintained) to @typegoose/typegoose
  • Change to your new automapper

I gave the changes a go but got hungup on the automapper changes, and then realized that's yours too. Figured I'd just ask...

Do you have time to npm-upgrade the server packages and give this a go in a new branch? I bet it'll only take you a quick minute, since you are so close to everything.

cadvisor errors out on windows

On windows Cadvisor errors out and has to be removed from the docker compose

ERROR: for cadvisor Cannot create container for service cadvisor: invalid volume specification: '/host_mnt/rootfs:ro' ERROR: Encountered errors while bringing up the project.

change the angular port

Setting things to 80 and 443 is a very bad idea as a lot of things use that on a client. Change it to something other than that or 8080 which is also heavily used.

Archived Repository

Hi everyone ๐Ÿ‘‹,

I sincerely thank everyone of you that takes interest in this repo (and possibly my tutorials on Medium and/or Youtube). Due to personal interest as well as busy work-load at work over the past year, I have not been able to maintain this repository to be up-to-date. For that, I am sorry for any inconveniences you might have run into while referencing this repository for your project.

With that in mind, I would also like to point out that both Angular and Nest have also seen many updates/changes. That's one other reason that I was hesitant to keep this repo up-to-date.

So what's the plan? I'd consider this repository to be Archived myself. On the other hand, I do have plan to work (and working) on a brand new MEAN tutorial with all the latest libraries (Angular 9, Nest 7, @typegoose/typegoose etc...). Please stay tuned.

As of this moment, I'll close all remaining issues. I might revisit this repository and archive the repo once I update it (if I could and if it does not turn into a fight over npm packages).

Again, thank you all for the support thus far. Feel free to reach out to me personally if you have any questions. See y'all around.

JWT_KEY not defined error in server

Starting the server via npm run start leads to the following error:

[Nest] 79352 - 2020-02-12 18:43 [ExceptionHandler] Configuration property "JWT_KEY" is not defined +4ms

A typo in the server/shared/utilities folder name.

First of thank you for the great tutorial. While I was going through it I found a typo in one of the folder names - /server/src/shared/utitlies/ should be /server/src/shared/utilities/ I believe. The issue is not breaking the code, because of the autoimport and thus is a bit hard to find.

  • Fix typo

unable to connect to mongodb

It's undocumented how to configure the mongodb connection and I can't figure out how to connect to it. I tried changing the configs according to an earlier issue and it won't connect.

Base controller implementation

Hello and thanks for the awesome tutorial in YouTube, now I'm asking for your help, I'm traying to implement a "BaseController" like this:

import {
  Body,
  Delete,
  Get,
  HttpException,
  HttpStatus,
  InternalServerErrorException,
  Param,
  Post,
  Put,
  Query,
} from '@nestjs/common';
import { UpdateResult } from 'typeorm';
import { BaseService } from './base.service';
import { ApiException } from '@models/api-exception.model';

export abstract class BaseController<T> {
  protected readonly service: BaseService<T>;

  constructor(service: BaseService<T>) {
    this.service = service;
  }

  @Get()
  root(@Query('filter') filter = {}): Promise<T[]> {
    try {
      return this.service.find(filter);
    } catch(e) {
      throw new HttpException(e, HttpStatus.INTERNAL_SERVER_ERROR);
    }
  }

  @Get(':id')
  getById(@Param('id') id: string | number): Promise<T> {
    try {
      return this.service.findById(id);
    } catch(e) {
      throw new HttpException(e, HttpStatus.INTERNAL_SERVER_ERROR);
    }
  }

  @Post()
  create(@Body() body: T): Promise<T> {
    try {
      return this.service.create(body);
    } catch(e) {
      throw new HttpException(e, HttpStatus.INTERNAL_SERVER_ERROR);
    }
  }

  @Put()
  update(@Body() body: { id: string | number } & T): Promise<UpdateResult> {
    return this.service.update(body.id, body);
  }

  @Delete(':id')
  delete(@Param('id') id: string | number) {
    try {
      return this.service.delete(id);
    } catch(e) {
      throw new InternalServerErrorException(e);
    }
  }
}

But how I could decorate my methods when I extends from this class

Remove .DS_Store

Remove the file .DS_Store and also add it to the .gitignore. I can open the PR for that

I'd like to replace mongo by MySQL

It's me again Mr. Chau from Youtube...
I'm here and i really hope you have to time to help growing up with NestJS.

Like i said, I had to deal with the diference between mongoose and mySql from 2nd video exactly in the configuration and mapper services ..

JWT_KEY issue

Hello, I also have some issues with the JWT_KEY key.

My config:

export enum Configuration {
    HOST = '192.168.99.101',
    PORT = '27017',
    MONGO_URI = 'mongodb://192.168.99.101:27017',
    JWT_KEY = 'MySecret!123'
}

My error:

$ npm start

> [email protected] start C:\github\nest-mean\server
> ts-node -r tsconfig-paths/register src/main.ts

WARNING: No configurations found in configuration directory:C:\github\nest-mean\server\config
WARNING: To disable this warning set SUPPRESS_NO_CONFIG_WARNING in the environment.
[Nest] 28264   - 10/02/2019, 4:22 PM   [NestFactory] Starting Nest application...
[Nest] 28264   - 10/02/2019, 4:22 PM   [InstanceLoader] MongooseModule dependencies initialized +22ms
[Nest] 28264   - 10/02/2019, 4:22 PM   [InstanceLoader] HttpModule dependencies initialized +2ms
[Nest] 28264   - 10/02/2019, 4:22 PM   [ExceptionHandler] Configuration property "MySecret!123" is not defined +14ms
Error: Configuration property "MySecret!123" is not defined
    at Config.get (C:\github\nest-mean\server\node_modules\config\lib\config.js:182:11)
    at ConfigurationService.get (C:\github\nest-mean\server\src\shared\configuration\configuration.service.ts:10:37)
    at new JwtStrategy (C:\github\nest-mean\server\src\shared\auth\strategies\jwt-strategy.service.ts:17:48)
    at Injector.instantiateClass (C:\github\nest-mean\server\node_modules\@nestjs\core\injector\injector.js:276:19)
    at callback (C:\github\nest-mean\server\node_modules\@nestjs\core\injector\injector.js:74:41)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at Object.<anonymous> (C:\github\nest-mean\server\node_modules\ts-node\src\bin.ts:158:12)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

greetings g.

[TS Lint Error] Array type using "T[]" is forbidden?

I am trying to create the base service. But i get tslint error. this is the method

async findAll(
    filter = {},
    selectFields: {}
  ): Promise<InstanceType<T>[]> {
    if (selectFields) {
      return this.model.find(filter).select(selectFields).exec();
    } else {
      return this.model.find(filter).exec();
    }
  }

nginx config is screwed up

On trying to start the docker compose, I get this on trying to start nginx, and I can't connect to the frontend.
nginx-angular | 2019/08/22 02:29:23 [emerg] 1#1: unexpected "}" in /etc/nginx/nginx.conf:40
nginx-angular | nginx: [emerg] unexpected "}" in /etc/nginx/nginx.conf:40

Type not assignable to type void

In base.service.ts the return line in clearCollection(), gives:
Type '{ ok?: number; n?: number; }' is not assignable to type 'void'.ts(2322)
I copy and pasted that section of the code from here to make sure there were no mistakes.
@nestjs 5.7.3
typegoose 5.5.0
typescript 3.3.3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.