What is the @nestjs/schedule module?
Answer
The @nestjs/schedule module enables cron jobs and scheduled tasks within a NestJS application. Import ScheduleModule.forRoot(). Decorate methods in a service with scheduling decorators: @Cron(CronExpression.EVERY_DAY_AT_MIDNIGHT) runs a method every midnight. @Cron('0 30 11 * * 1-5') uses a custom cron expression. @Interval(10000) runs every 10 seconds. @Timeout(5000) runs once after a 5-second delay. Jobs are registered at startup and managed by the scheduler. Access and control jobs programmatically with the SchedulerRegistry. In distributed environments (multiple instances), only one instance should run scheduled jobs — use a lock mechanism (e.g., Redis) to prevent duplicate execution.
Previous
What is the NestJS interceptor for response transformation?
Next
How does NestJS handle circular dependencies?
More NestJS Questions
View all →- Intermediate How does NestJS dependency injection scoping work?
- Intermediate What are NestJS microservices and what transports are supported?
- Intermediate What is the ExecutionContext in NestJS?
- Intermediate How do you implement role-based access control (RBAC) in NestJS?
- Intermediate What is the Reflector in NestJS and how is it used?