Git Product home page Git Product logo

nest-template-redis-auth's Introduction

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.

NPM Version Package License NPM Downloads Travis Linux Coverage Gitter Backers on Open Collective Sponsors on Open Collective

Description

Nest framework TypeScript starter template.

This template use REST API concept. The flow of simple CRUD (Create, Read, Update and Delete) applications can be described using the following steps:

  1. The controllers layer handles HTTP requests and delegates tasks to the services layer.
  2. The services layer is where most of the business logic lives.
  3. Services use repositories / DAOs to change / persist entities.
  4. Entities act as containers for the values, with setters and getters.

Folder structure

+-- config // Environment config files.
+-- src // Sources files
|   +-- auth
|   |   +-- guards // Guards.
|   |   +-- strategies // Authentication stratergies.
|   +-- common // Common files.
|   |   +-- constants // Common constants.
|   |   +-- decorators // Common decorators.
|   |   +-- interceptors // Common interceptors.
|   |   +-- response // General response definition.
|   |   +-- serializers // Common serializers.
|   +-- configs // Configurations folder.
|   |   +-- app // Application config.
|   |   +-- database // Database config.
|   +-- modules // Bussiness Modules.
|   |   +-- users // Example user module.
|   |   |   +-- dto // DTO (Data Transfer Object) Schema, Validation.
|   |   |   +-- user.entity.ts // TypeORM Entities.
|   |   |   +-- users.constants.ts // Example constants file.
|   |   |   +-- users.controller.ts // Example controller.
|   |   |   +-- users.module.ts // Example module file.
|   |   |   +-- users.repository.ts // Example repository.
|   |   |   +-- users.service.ts // Example service.
|   |   +-- ... // Other business modules.
+-- test // Jest testing.
+-- app.controller.ts // App controller.
+-- app.module.ts // App module file.
+-- app.service.ts // App service.
+-- main.ts // Main.

File Naming for Class

export class PascalCaseSuffix {} //= pascal-case.suffix.ts
// Except for suffix, PascalCase to hyphen-case
class FooBarNaming {} //= foo-bar.naming.ts
class FooController {} //= foo.controller.ts
class BarQueryDto {} //= bar-query.dto.ts

Interface Naming

// https://stackoverflow.com/questions/541912
// https://stackoverflow.com/questions/2814805
interface User {}
interface CustomeUser extends User {}
interface ThirdCustomeUser extends CustomeUser {}

Setting up

IDE/Editor

  • IntelliJ WebStorm
  • Any editor: Visual Studio Code, Sublime, Atom,...

Environment variable

  1. Create config/development.env and config/prodution.env based on config/sample.env.
  2. Modify config/development.env and config/production.env files for each environment.
  3. Modify src/configs/configs.constants.ts to import these environment values to the project.

Database

  • This template use TypeORM as Object–relational mapping library.
  • TypeORM supports many database programs.
  • Detail configuration can be done in src/configs/database/typeorm.config.ts.
  • By default, the project is configured to use PostgreSQL relational database management system.

Intantiate a module

See NestJS CRUD generator.

  • Default:
$ nest g resource modules/<module-name>

Select REST API. NestJS CLI will generate a boilerplate for the module.

  • If the structure is more complex:
$ nest g resource <module-name>

Copy the generated module to src/modules/<your desired folder>.

Logging

  1. development will log ['log', 'debug', 'error', 'verbose', 'warn'] levels.
  2. production will log ['error', 'warn'] levels.
  • Logging levels can be customized in main.ts for each environment.

Installation

Install npm packages

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Documentation

Swagger

# API, Swagger - src/swagger.ts
npm run doc:api #> http://localhost:3000/api
  • This project ultilize NestJS's CLI Plugin .
  • Please aware that there is no need to put @ApiProperty decorator for every DTOs properties. For more information, please visit the link above.

Dependency

"dependencies": {
    "@nestjs/common": "^7.0.0",
    "@nestjs/config": "^0.5.0",
    "@nestjs/core": "^7.0.0",
    "@nestjs/jwt": "^7.2.0",
    "@nestjs/passport": "^7.1.0",
    "@nestjs/platform-express": "^7.0.0",
    "@nestjs/swagger": "^4.7.4",
    "@nestjs/typeorm": "^7.1.4",
    "@types/bcrypt": "^3.0.0",
    "@types/passport-facebook": "^2.1.10",
    "bcrypt": "^5.0.0",
    "class-transformer": "^0.3.1",
    "class-validator": "^0.12.2",
    "dotenv": "^8.2.0",
    "passport": "^0.4.1",
    "passport-facebook": "^3.0.0",
    "passport-google-oauth": "^2.0.0",
    "passport-google-oauth20": "^2.0.0",
    "passport-jwt": "^4.0.0",
    "pg": "^8.5.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^6.5.4",
    "swagger-ui-express": "^4.1.4",
    "tslint": "^6.1.3",
    "typeorm": "^0.2.29",
    "uuid": "^8.3.1"
  },

License

Nest is MIT licensed.

nest-template-redis-auth's People

Contributors

billyant24 avatar

Stargazers

 avatar

Watchers

 avatar

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.