ack-nestjs-mongoose is a NestJs Boilerplate with Mongoose and MongoDB as Database.
Made with following
- Repository Design Pattern
- Microservice Architecture
- NestJs Habit.
- The Twelve-Factor App
You can Request Feature or Report Bug with following this link
ack-nestjs-mongoose still on trial and error phase and the test will base on real projects or cases. So there will be (always) have new update and new features.
If you change env value of APP_MODE
to secure
that will trigger more Middleware
and Guard
.
TimestampMiddleware
, tolerant 5 minutes of request.UserAgentMiddleware
, whitelist of user agent.ApiKeyGuard
, check api key based on database.
If you change env value of APP_ENV
to production
that will
- Do not write into console
Database debug
even whenDATABASE_DEBUG
istrue
- Do not write into console for
DebuggerService
even whenAPP_DEBUG
istrue
CorsMiddleware
on.
You can see our e2e testing file
or read the documentation on [section environment][ack-doc-env].
Describes which version .
Name | Version |
---|---|
NestJs | v9.x |
NodeJs | v18.x |
Typescript | v4.x |
Mongoose | v6.x |
MongoDB | v6.x |
Yarn | v1.x |
NPM | v8.x |
Docker | v20.x |
Docker Compose | v2.x |
ack-nestjs-mongoose have some objective.
- Simple, scalable and secure
- Avoid spaghetti code
- Component based
- Reusable component
- Easy to maintenance
- Support for all microservice patterns
- NestJs v9.x ๐ฅณ
- Production Ready ๐ฅ
- Typescript ๐
- Authentication and Authorization (JWT, OAuth2, API Key, Basic Auth, Role Management) ๐ช
- User Agent Check
- MongoDB Integrate by Using Mongoose Package ๐
- Database Migration (NestJs-Command)
- Storage with AWS (S3)
- Server Side Pagination (3 Types)
- Url Versioning
- Request Validation Pipe with Custom Message ๐
- Custom Error Status Code ๐คซ
- Logger (Morgan) and Debugger (Winston) ๐
- Centralize Configuration ๐ค
- Centralize Exception Filter, and Custom Error Structure
- Multi-language (i18n) ๐ฃ
- Timezone Awareness, and Custom Timezone
- Request Timeout, and Request Custom Timeout (Override) โ๏ธ
- Dynamic Setting from Database ๐ฟ
- Maintenance Mode on / off ๐ค
- Server Side Pagination
- Cache Manager Implementation
- Support Docker Installation
- Support CI/CD with Github Action or Jenkins
- Husky GitHook For Check Source Code, and Run Test Before Commit ๐ถ
- Linter with EsLint for Typescript
We assume that everyone who comes here is programmer with intermediate knowledge
and we also need to understand more before we begin in order to reduce the knowledge gap.
- Understand NestJs Fundamental, Main Framework. NodeJs Framework with support fully TypeScript.
- UnderstandTypescript Fundamental, Programming Language. It will help us to write and read the code.
- Understand ExpressJs Fundamental, NodeJs Base Framework. It will help us in understanding how the NestJs Framework works.
- Understand what NoSql is and how it works as a database, especially MongoDB.
- Optional, Understand Microservice Architecture and the design pattern.
- Optional,The Twelve Factor Apps
- Optional, Understand Docker that can help you to run the project
Next development
- Import data form excel
- Version 2. New folder structure, new file upload decorator
- Reduce mixin usage
- Upload file multiple update
- File large upload into s3 for video and audio. using array of chunk
- Rename repo from
ack-nestjs-boilerplate-mongoose
toack-nestjs-mongoose
- Message en,id
- Optimize code, remove unnecessary code
- Update Unit test
- Update E2E test
- Response Excel, convert response from controller into excel
res.send()
- Implement Repository Design Pattern
- Swagger for API Documentation
- Basic Token as ApiKey
- Update Documentation
Before we start, we need to install some packages and tools. Recommend version is LTS Version for every tool and package.
Make sure check that tools has been installed successfully.
Clone ack-nestjs-mongoose with git.
git clone https://github.com/andrechristikan/ack-nestjs-mongoose
This project need some dependencies. Let's go install it.
# yarn
yarn install
Make your own environment with copy from .env.example
and edit some value.
cp .env.example .env
If you want to to implement
transaction
, you must to installMongodb Replication Set
. You need to runmongodb
. There are have so many options, you can do by your self with search on
Database migration ack-nestjs-mongoose used NestJs-Command
For migrate
yarn migrate
For rollback
yarn rollback
ack-nestjs-mongoose provide 3 automation testing unit testing
, integration testing
, and e2e testing
.
yarn test
For unit testing
yarn test:unit
For integration testing
yarn test:integration
For E2E testing
yarn test:e2e
If mongodb version < 5, Read this section for adjust mongoose setting.
Finally, Cheers ๐ป๐ป !!! we passed all steps.
Now we can run ack-nestjs-mongoose and use all of features.
yarn start:dev
docker-compose up -d
Detail information about the environment
Key | Type | Description |
---|---|---|
APP_NAME | string |
Application name and will be subject for jwt |
APP_ENV | string |
|
APP_MODE | string |
|
APP_LANGUAGE | string |
Enum languages, separator , |
APP_TZ | string |
Override timezone |
APP_HOST | string |
Application serve |
APP_PORT | number |
Application serve |
APP_DEBUG | boolean |
All logs will write into console |
APP_VERSIONING | boolean |
Application url versioning |
APP_VERSION | `number | string` |
APP_HTTP_ON | boolean |
Application Http turn on |
APP_JOB_ON | boolean |
Application Job turn on |
Key | Type | Description |
---|---|---|
DATABASE_HOST | string |
Mongodb URL. Support standard url replication , and srv |
DATABASE_NAME | string |
Database name |
DATABASE_USER | string |
Database user |
DATABASE_PASSWORD | string |
Database user password |
DATABASE_DEBUG | boolean |
Trigger database mongoose DEBUG |
DATABASE_OPTIONS | string |
Mongodb connect options |
Key | Type | Description |
---|---|---|
MIDDLEWARE_TOLERANCE_TIMESTAMP | string |
Tolerance timestamp ApiKey . ms package value |
MIDDLEWARE_TIMEOUT | string |
Request timeout. ms package value |
Key | Type | Description |
---|---|---|
AUTH_JWT_AUDIENCE | string |
Jwt audience |
AUTH_JWT_ISSUER | string |
JWT issuer |
AUTH_JWT_ACCESS_TOKEN_SECRET_KEY | string |
Secret access token, free text. |
AUTH_JWT_ACCESS_TOKEN_EXPIRED | string |
Expiration time for access token. ms package value |
AUTH_JWT_REFRESH_TOKEN_SECRET_KEY | string |
Secret refresh token, free text. |
AUTH_JWT_REFRESH_TOKEN_EXPIRED | string |
Expiration time for refresh token. ms package value |
AUTH_JWT_REFRESH_TOKEN_REMEMBER_ME_EXPIRED | string |
Expiration time for refresh token when remember me is checked. ms package value |
AUTH_JWT_REFRESH_TOKEN_NOT_BEFORE_EXPIRATION | string |
Token active for refresh token before x time. ms package value |
Will implement as
ApiKey
Key | Type | Description |
---|---|---|
AUTH_BASIC_TOKEN_CLIENT_ID | string |
Free text |
AUTH_BASIC_TOKEN_CLIENT_SECRET | string |
Free tex |
Key | Type | Description |
---|---|---|
AWS_CREDENTIAL_KEY | string |
AWS account credential key |
AWS_CREDENTIAL_SECRET | string |
AWS account credential secret |
AWS_S3_REGION | string |
AWS S3 Region |
AWS_S3_BUCKET | string |
AWS S3 Name of Bucket |
Just is case, if your mongodb version is < 5
Go to file src/common/database/services/database.options.service.ts
and remove comment useMongoClient
then set value to true
.
const mongooseOptions: MongooseModuleOptions = {
uri,
useNewUrlParser: true,
useUnifiedTopology: true,
serverSelectionTimeoutMS: 5000,
useMongoClient: true
};
Distributed under MIT licensed.