nestjs-bullmq-postgresql starter kit
This starter kit features NestJS, BullMQ and PostgreSQL.
Tech Stack
Included Tooling
CLI Installation
You can choose from either npm, yarn or pnpm to install the kit.
npm create @this-dot/starter -- --name my-project-name --kit nestjs-bullmq-postgresql
yarn create @this-dot/starter --name my-project --kit nestjs-bullmq-postgresql
pnpm create @this-dot/starter --name my-project-name --kit nestjs-bullmq-postgresql
Follow these set of directions to finish setting up your kit.
cdinto your project directory and runnpm install(oryarn,pnpm).- Make sure you have docker installed on your machine.
- Create a
.envfile and copy the contents of the.env.exampleinto it. - Create a
.postgres.db.envfile and copy the contents of the.postgres.db.env.exampleinto it. - Run
npm run infrastructure:start(oryarn,pnpm) to start the database. - Run
npm run start(oryarn,pnpm) to start the development server.
Manual installation
git clone https://github.com/thisdot/starter.dev.git
- Copy and rename the
starters/nestjs-bullmq-postgresqldirectory to the name of your new project. - Make sure you have docker installed on your machine.
cdinto your project directory and runnpm install(oryarn,pnpm).- Create a
.envfile and copy the contents of the.env.exampleinto it. - Create a
.postgres.db.envfile and copy the contents of the.postgres.db.env.exampleinto it. - Run
npm run infrastructure:start(oryarn,pnpm) to start the database. - Run
npm run start(oryarn,pnpm) to start the development server.
Built-in Scripts
npm run infrastructure:start- Creates and starts all the Docker containers for services from the Docker Compose configuration.npm run infrastructure:stop- Stops all of the Docker containers for services from the Docker Compose configuration.npm run start- Starts the Nest application on a local servernpm run build- Builds the Nest applicationnpm run format- Formats the entire codebase using Prettiernpm run lint- Checks the entire project with ESLintnpm run test- Runs the Jest test suitenpm run test:e2e- Runs the e2e test suite
Kit Organization / Architecture
Inside the src directory, you will find the code for the health check, queue and technology example CRUD implementations.
.
├── health
│ ├── health.controller.ts
│ └── health.module.ts
├── queue
│ ├── queue.controller.ts
│ ├── queue.module.ts
│ └── queue.processor.ts
├── technology
│ ├── dto
│ │ └── create-technology.dto.ts
│ ├── technology.controller.spec.ts
│ ├── technology.controller.ts
│ ├── technology.model.ts
│ ├── technology.module.ts
│ └── technology.service.ts
├── app.module.ts
└── main.ts
Health check
Inside the src/health/health.controller.ts file, you will find the HealthController which uses the @nestjs/terminus package to check on the health of your application.
@Controller('health')
export class HealthController {
constructor(private health: HealthCheckService, private db: SequelizeHealthIndicator) {}
@Get()
@HealthCheck()
checkHealth() {
return this.health.check([() => this.db.pingCheck('sequelize')]);
}
}
You can check on the health of your app by starting the local server and going to the http://localhost:3000/health endpoint.
Queue
Inside the src/queue/queue.processor.ts file, you will find an example QueueProcessor class that uses BullMQ.
@Processor('queue')
class QueueProcessor extends WorkerHost {
async process(job: Job<any, any, string>): Promise<any> {
console.log(`Processing job ${job}`);
}
@OnWorkerEvent('completed')
onCompleted() {
console.log('Job Completed');
}
}
Technology example
Inside the src/technology directory, you will find an example of a technology CRUD implementation with tests.
create(createTechnologyDto: CreateTechnologyDto): Promise<Technology> {
return this.technologyModel.create({
displayName: createTechnologyDto.displayName,
description: createTechnologyDto.description,
url: createTechnologyDto.url,
});
}
Swagger UI
This starter kit uses Swagger UI to show the REST API documentation for the technology and health API’s.
You can view the documenation at http://localhost:3000/api
