A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.
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:
- The controllers layer handles HTTP requests and delegates tasks to the services layer.
- The services layer is where most of the business logic lives.
- Services use repositories / DAOs to change / persist entities.
- Entities act as containers for the values, with setters and getters.
+-- 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.
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
// https://stackoverflow.com/questions/541912
// https://stackoverflow.com/questions/2814805
interface User {}
interface CustomeUser extends User {}
interface ThirdCustomeUser extends CustomeUser {}
- IntelliJ WebStorm
- Any editor: Visual Studio Code, Sublime, Atom,...
- Create
config/development.env
andconfig/prodution.env
based onconfig/sample.env
. - Modify
config/development.env
andconfig/production.env
files for each environment. - Modify
src/configs/configs.constants.ts
to import these environment values to the project.
- 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.
- 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>
.
- See NestJS Logger.
- By default:
development
will log['log', 'debug', 'error', 'verbose', 'warn']
levels.production
will log['error', 'warn']
levels.
- Logging levels can be customized in
main.ts
for each environment.
$ npm install
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
# 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.
"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"
},
Nest is MIT licensed.