Giter Site home page Giter Site logo

onix-systems / nest-js-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
216.0 10.0 40.0 3.67 MB

Nest.js boilerplate

Home Page: https://onix-systems.com/

License: MIT License

JavaScript 5.09% Shell 0.02% TypeScript 91.11% Handlebars 3.77% Dockerfile 0.01%
generator typescript nestjs rest-api api boilerplate starter-kit starter jwt passport

nest-js-boilerplate's People

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

nest-js-boilerplate's Issues

Improve Serialize Interseptor

example of new interseptor:

import {
  CallHandler,
  ExecutionContext,
  Injectable,
  NestInterceptor,
} from '@nestjs/common';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { getSerializeType } from '@decorators/serialization.decorator';

@Injectable()
export default class SerializeInterceptor implements NestInterceptor {
  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    return next.handle().pipe(
      map((args) => {
        const SerializeType = getSerializeType(context.getHandler());
        const entity = new SerializeType();
        if (Array.isArray(args)) {
          if (args && args[0] && args[0].toJSON) {
            return Object.assign(entity, { data: args.map((doc) => doc.toJSON()) });
          }
          return Object.assign(entity, { data: args });
        }

        if (args && args.toJSON) {
          return Object.assign(entity, { data: args.toJSON() });
        }

        return Object.assign(entity, args);
      }),
    );
  }
}

Lets start work with mongoose instance and change all repository

lean() -> exec()

Bcrypt fails install

Issue: Bcrypt isn't installing with issues raised as GYP
Identified Problem: NPM isn't installing key libraries for Bcrypt

Resolution: Due to "Yo" using NPM, Bcrypt will not install and so the installation is failing as an issue with "Node-GYP". We've found by our own investigation that it is NPM causing the issues, as we switched the install from NPM install bcrypt to yarn add bcrypt and it fully installs without any issues.

Could you switch the generator to use Yarn?

Wrong path for packages.json

During install generator stops with error below. Seems like a problem in wrong path, cause files was generated in /Users/denis/Projects/node/todojazz but in in dump I see path /Users/denis/Projects/node/package.json

node:events:368
      throw er; // Unhandled 'error' event
      ^

AssertionError [ERR_ASSERTION]: Trying to copy from a source that does not exist: /Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/generator-nest-js-boilerplate/generators/auth/templates/postgresql/oauth2/src/modules/
    at EditionInterface.exports.copy (/Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/generator-nest-js-boilerplate/node_modules/mem-fs-editor/lib/actions/copy.js:49:3)
    at EditionInterface.module.exports [as copyTpl] (/Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/generator-nest-js-boilerplate/node_modules/mem-fs-editor/lib/actions/copy-tpl.js:28:8)
    at AuthenticationGenerator.module.exports (/Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/generator-nest-js-boilerplate/generators/auth/steps/writing.js:27:11)
    at Object.<anonymous> (/Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/generator-nest-js-boilerplate/node_modules/yeoman-generator/lib/index.js:991:25)
    at /Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/generator-nest-js-boilerplate/node_modules/run-async/index.js:49:25
    at new Promise (<anonymous>)
    at /Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/generator-nest-js-boilerplate/node_modules/run-async/index.js:26:19
    at runLoop.add.once.once (/Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/generator-nest-js-boilerplate/node_modules/yeoman-generator/lib/index.js:992:11)
    at Immediate._onImmediate (/Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/yo/node_modules/grouped-queue/lib/subqueue.js:48:34)
    at processImmediate (node:internal/timers:464:21)
Emitted 'error' event on AuthenticationGenerator instance at:
    at Immediate.<anonymous> (/Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/generator-nest-js-boilerplate/node_modules/yeoman-generator/lib/index.js:1022:20)
    at processImmediate (node:internal/timers:464:21) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}
❯ npm start
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /Users/denis/Projects/node/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/Users/denis/Projects/node/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/denis/.npm/_logs/2022-05-12T21_15_06_152Z-debug.log

/Users/denis/Projects/node/package.json

Dependencies exception during app generation

Seems like a problem with dependencies conflict:

npm ERR! code ETARGET
npm ERR! notarget No matching version found for [email protected].
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/denis/.npm/_logs/2022-05-12T21_27_10_388Z-debug.log

Improve response format

 return res.status(HttpStatus.BAD_REQUEST).json({
        messages: ['string', 'string'],
        error: 'string',
});

Error during app generation

During install I see the error:

394 verbose type range
395 verbose stack bson: No matching version found for bson@^4.6.2.
395 verbose stack     at module.exports (/Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/npm/node_modules/npm-pick-manifest/index.js:209:23)
395 verbose stack     at /Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/npm/node_modules/pacote/lib/registry.js:118:26
396 verbose cwd /Users/denis/Projects/node/todojazz

It's especially seems like a problem because I didn't install mongo driver

Dependency missing errors

Dependency missing errors

Ubuntu: 20.04.3 LTS 64-bit

Node.js version: 16.13.2

NPM version: 8.1.2

Boilerplate configuration:

PM: npm,
Install stable packages?: yes
Application settings: default,
Auth: jwt,
Json Api: no
DataBase: MySQL,
Emails: no,
WebSockets: no,
Docker container: yes,
Heroku: no

Errors while installing:

npm ERR! > [email protected] prepublish
npm ERR! > yarn run build
......
npm ERR! sh: 1: yarn: not found
npm ERR! npm ERR! code 127

Errors after starting project:

Cannot find module '@nestjs/passport'
Cannot find module '@nestjs/jwt'
Cannot find module 'nestjs-redis'
Cannot find module 'ioredis'
// And after manually installing this packages appears new errors
Error: Cannot find module 'passport-local'
Error: Cannot find module 'passport-jwt'

After installing missing dependencies appears new error:

ERROR [ExceptionHandler] Nest can't resolve dependencies of the RedisCoreModule (Symbol(REDIS_MODULE_OPTIONS), ?). Please make sure that the argument ModuleRef at index [1] is available in the RedisCoreModule context.

It can be resolved by replacing nestjs-redis module by @liaoliaots/nestjs-redis package and modifying RedisModule code in app.module.ts file:

// New code for RedisModule
RedisModule.forRoot({
      config: {
        url: process.env.REDIS_URL,
      },
}),

After all of this work you will be able to successfully start application

Types declaration issue in generated packages

src/modules/app/app.module.ts:2:31 - error TS2307: Cannot find module '@nestjs/typeorm' or its corresponding type declarations.

2 import { TypeOrmModule } from '@nestjs/typeorm';
                                ~~~~~~~~~~~~~~~~~
src/modules/v1/users/schemas/user.entity.ts:6:8 - error TS2307: Cannot find module 'typeorm' or its corresponding type declarations.

6 } from 'typeorm';
         ~~~~~~~~~
src/modules/v1/users/users.module.ts:2:31 - error TS2307: Cannot find module '@nestjs/typeorm' or its corresponding type declarations.

2 import { TypeOrmModule } from '@nestjs/typeorm';
                                ~~~~~~~~~~~~~~~~~
src/modules/v1/users/users.repository.ts:2:34 - error TS2307: Cannot find module '@nestjs/typeorm' or its corresponding type declarations.

2 import { InjectRepository } from '@nestjs/typeorm';
                                   ~~~~~~~~~~~~~~~~~
src/modules/v1/users/users.repository.ts:3:28 - error TS2307: Cannot find module 'typeorm/index' or its corresponding type declarations.

3 import { Repository } from 'typeorm/index';
                             ~~~~~~~~~~~~~~~
src/modules/v1/users/users.repository.ts:4:32 - error TS2307: Cannot find module 'typeorm/find-options/FindConditions' or its corresponding type declarations.

4 import { FindConditions } from 'typeorm/find-options/FindConditions';

docker-compose up error

Hello really great work here! I am using an M1 Mac and after having to force install node modules npm run start:dev does not work which is a separate issue and I then try the docker-compose up command also and get this below. I think it's just the git installation that is the issue.

oyinkay@Oyinkansolas-MacBook-Air momo-backend % docker-compose up
Building app
[+] Building 6.9s (10/11)
=> [internal] load build definition from App.Dockerfile 0.1s
=> => transferring dockerfile: 41B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/node:16-slim 2.5s
=> [auth] library/node:pull token for registry-1.docker.io 0.0s
=> [internal] load build context 3.5s
=> => transferring context: 4.98MB 3.1s
=> [1/6] FROM docker.io/library/node:16-slim@sha256:3c8acd4934617f6 0.0s
=> CACHED [2/6] WORKDIR /var/www/app 0.0s
=> CACHED [3/6] RUN apt-get update 0.0s
=> CACHED [4/6] COPY . . 0.0s
=> ERROR [5/6] RUN apt-get install -y git 0.7s

[5/6] RUN apt-get install -y git:
#10 0.651 Reading package lists...
#10 0.657 Building dependency tree...
#10 0.658 Reading state information...
#10 0.658 E: Unable to locate package git


executor failed running [/bin/sh -c apt-get install -y git]: exit code: 100
ERROR: Service 'app' failed to build : Build failed

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.