node.jscronnestjsscheduled-taskscron-task

What is the default timezone for nestjs cron (@Cron) decorator


I am writing a cron to run at midnight every day in Indian Standard Time.

@Injectable()
export class CronService {

  @Cron("0 0 * * *")
  async midnightCron() {
    // implementation
  }

}

My instance is deployed in AWS Mumbai region.

I want to know if the @Cron decorator uses local time or UTC time for execution ?


Solution

  • The cron package that NestJS uses just works based on the TZ environment variable if no timezone is passed to it when scheduling the task. This is a default environment variable that usually reflects the system's clock, but can be set to UTC to have Node's Date class function as if it were always in UTC time.