
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
@nestjs/schedule
Advanced tools
@nestjs/schedule is a scheduling module for NestJS applications that allows you to easily create and manage scheduled tasks. It provides decorators and utilities to define cron jobs, timeouts, and intervals in a declarative way.
Cron Jobs
This feature allows you to define cron jobs using the @Cron decorator. The example demonstrates a task that runs every 10 seconds.
```typescript
import { Injectable } from '@nestjs/common';
import { Cron, CronExpression } from '@nestjs/schedule';
@Injectable()
export class TasksService {
@Cron(CronExpression.EVERY_10_SECONDS)
handleCron() {
console.log('Called every 10 seconds');
}
}
```
Timeouts
This feature allows you to define one-time tasks that execute after a specified delay using the @Timeout decorator. The example demonstrates a task that runs once after 5 seconds.
```typescript
import { Injectable } from '@nestjs/common';
import { Timeout } from '@nestjs/schedule';
@Injectable()
export class TasksService {
@Timeout(5000)
handleTimeout() {
console.log('Called once after 5 seconds');
}
}
```
Intervals
This feature allows you to define recurring tasks that execute at specified intervals using the @Interval decorator. The example demonstrates a task that runs every 10 seconds.
```typescript
import { Injectable } from '@nestjs/common';
import { Interval } from '@nestjs/schedule';
@Injectable()
export class TasksService {
@Interval(10000)
handleInterval() {
console.log('Called every 10 seconds');
}
}
```
node-cron is a lightweight npm package for scheduling tasks in Node.js using cron syntax. It is not specific to any framework and can be used in any Node.js application. Compared to @nestjs/schedule, node-cron provides a more general-purpose solution but lacks the integration and decorators provided by NestJS.
Agenda is a job scheduling package for Node.js with MongoDB as a backend. It provides a more feature-rich solution for job scheduling, including job persistence, retries, and job prioritization. Compared to @nestjs/schedule, Agenda offers more advanced features but requires additional setup and configuration.
Bull is a Redis-based queue system for Node.js that supports job scheduling, retries, and concurrency. It is designed for handling background jobs and tasks. Compared to @nestjs/schedule, Bull is more suitable for complex job processing scenarios and provides more control over job execution and management.
A progressive Node.js framework for building efficient and scalable server-side applications.
Schedule module for Nest based on the cron package.
$ npm install --save @nestjs/schedule
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
Nest is MIT licensed.
FAQs
Nest - modern, fast, powerful node.js web framework (@schedule)
The npm package @nestjs/schedule receives a total of 1,166,370 weekly downloads. As such, @nestjs/schedule popularity was classified as popular.
We found that @nestjs/schedule demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.