Nest Boilerplate Project is powered by Nest
Please use a template from README.sample.md for your real project README.md. An example can be found in README.example.md
Powered by Nest and Typescript, this boilerplate project will make your life easier when setup a new project without worrying too much about the architecture, routing, validation, middleware, ...etc. This boilerplate project can be fully customized to your needs.
Thanks to VSCode and Typescript, we will have a fully intellisense when coding. No more magic function names appear out of nowhere, or some global functions that we have no idea where it is located.
We want to hear your feedback and your suggestion on this project to make it more powerful, robust and dynamic.
Also Read How to become a back-end developer
Check your environment variables
To set your application environment variables create a
.env
file. There is an.env.example
file to follow.
Install dependencies
yarn install
Run in development environment
# running nodemon
yarn dev
Run in production environment
# compile typescript
yarn build
# compile and run with pm2
yarn start
Structure your solution by self-contained components
•
├── 📁assets # Contain any files for your app. ex: email template, static data json
├── 📁config # Contain any configuration from a third party library. ex: firebase config
├── 📁public # Contain access files via public
├── 📁src # Main directory that stores all the business logic
│ ├── 📁api # Yes, Api you know it
│ ├── 📁common # Contain your custom functions
│ ├── 📁lib # Built-In modules
│ ├── 📁models # Contain Sequelize models
│ ├── 📁queries # Contain raw SQL files
│ ├── 📁schema # Contain Mongodb schema
│ ├── 📄app.module.ts # Contain in-app modules
│ └── 📄index.ts # Server configuration and startup
- Config
- Firebase Admin
- Google Cloud Storage
- Mailer
- Mongoose
- Redis
- S3
- Sequelize
- Socket
- Authentication
- Cron Scheduler
- Multer Upload
- Social
- Excel
This project will not have the feature you need or you don't need any of our features. To simply start to project, you have to take a look into some files.
This project is no doubt using express as a default. If you are familiar with express then you are good to go. You can set any configuration, setting, middleware, document within this file.
async function bootstrap() {
const app = await NestFactory.create(ApplicationModule);
// =================================
// configureExpressSettings
// =================================
app.set();
// =================================
// configureExpressMiddleware
// =================================
app.use();
// =================================
// configureNestGlobals
// =================================
app.useGlobalGuards();
app.useGlobalFilters();
app.useGlobalPipes();
// =================================
// configureNestSwagger
// =================================
const options = new DocumentBuilder()
.setTitle('Nest Boilerplate Project')
.setContact('Dominic Preap', 'https://github.com/Dominic-Preap', 'preapchanoudom@gmail.com')
.setVersion('1.0')
.addBearerAuth()
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('/docs', app, document);
}
This file controls all of your module. The required module for this file is ApiModule
and ConfigModule
. Un-comment the module that you need.
ApiModule
stores every route handlers, business logic, and task scheduler as such.ConfigModule
stores and validates environment file.env
.
import { Module } from '@nestjs/common';
import { ConfigModule } from '@lib/config';
import { ApiModule } from './api/api.module';
@Module({
imports: [ApiModule, ConfigModule]
})
export class ApplicationModule {}