npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@optask/nestjs

v1.2.1

Published

A wrapper around tasker base for nestjs, providing custom decorators

Readme

@optask/nestjs

A wrapper package that allows usage of @optask/tasker within a nestjs application.

Quickstart

Install tasker and nestjs plugin:

yarn add @optask/tasker @optask/nestjs

First create a task you want to run:

import { Injectable } from '@nestjs/common';
import { Task, BaseTask } from '@optask/nextjs';

@Injectable()
@Task({
  name: 'task',
})
class MyTask extends BaseTask {
  run() {
    // do something
  }
}

note you must extend BaseTask and use the @Task decorator for the task to be registered successfully.

Then create a module that provides this task:

import { Module } from '@nestjs/common';

import { MyTask } from './MyTask';

@Module({
    providers: [MyTask],
    exports: [MyTask],
});
export class TaskModule {}

Finally, import this module and register the scheduler module:

import { Module } from '@nestjs/common';
import { TaskSchedulerModule } from '@optask/nestjs';
import { InMemoryStore } from '@optask/tasker';

import { TaskModule } from './TaskModule';
import { RunTasker } from './RunTasker';

@Module({
  imports: [
    TaskSchedulerModule.register({
      imports: [TaskModule],
      store: new InMemoryStore(), // Use a real store here if you need it!
    }),
  ],
  providers: [RunTasker],
})
export class AppModule {}

Then the scheduler service can be used to run the tasks:

import { Injectable } from '@nestjs/common';
import { TaskSchedulerService } from '@optask/nestjs';

@Injectable()
export class TaskRunner {
    constructor(private readonly scheduler: TaskSchedulerService){}

    async run() {
        // Do any editing you need to
        this.scheduler.addCondition('myCondition', 'test');

        // Run the tasks
        await this.scheduler.run();
    }
}

Creating Tasks

Tasks are providers registered in the scheduler with the @Task decorator. They should extend BaseTask from this library, which provides the base implementation of a task in tasker.

You can optionally provide the task's run condition, modifiers, and dependencies as well with the provided metadata to the @Task decorator. See the @optask/tasker documentation for information on task conditions, modifiers, and dependencies.

For example, to define a task that would run once on each version on a pre deploy step, and depends on a task called migrate, you could pass this configuration:

import { Injectable } from '@nestjs/common';
import { Task, BaseTask } from '@optask/nestjs';
import { EqualsCondition, RunOnceModifier } from '@optask/tasker';

@Injectable()
@Task({
  name: 'validate',
  dependencies: ['migrate'],
  condition: new EqualsCondition('step', 'pre-deploy'),
  modifiers: [new RunOnceModifier(['version'])],
})
export class ValidateTask extends BaseTask {
  async run() {
    // do some validation here
  }
}

Setting the task scheduler conditions

In the above example, we need the conditions of version and step to be defined. To do so, you can provide the conditions directly in the register method of the TaskSchedulerModule

Here is an example of providing the configuration directly:

import { Module } from '@nestjs/common';
import { TaskSchedulerModule } from '@optask/nestjs';
import { FileSystemStore } from '@optask/tasker';

@Module({
  imports: [
    TaskSchedulerModule.register({
      imports: [ModuleWithTasks],
      store: new FileSystemStore(),
      conditions: {
        step: process.env.STEP,
        version: process.env.VERSION,
      },
    }),
  ],
})
export class AppModule {}

You can also use another provider that implements the ConfigurationProvider interface (or both!)

import { Module } from '@nestjs/common';
import { TaskSchedulerModule } from '@optask/nestjs';
import { FileSystemStore } from '@optask/tasker';

@Module({
  imports: [
    TaskSchedulerModule.register({
      imports: [ModuleWithTasksAndConditionProvider],
      store: new FileSystemStore(),
      conditions: {
        step: `pre-deploy`,
      },
      conditionsProvider: MyConditionsProvider, // Make sure this is provided from the imported modules
    }),
  ],
})
export class PreDeployModule {}

Example of a conditions provider:

import { Injectable } from '@nestjs/common';
import { ConditionsProvider } from '@optask/nestjs';

@Injectable()
export class MyConditionsProvider implements ConditionsProvider {
    async getConditions() {
        const version = await getVersion(); // can be async or pull from another injected provider

        return {
            version,
        };
    }
}

In the above example, the conditions will get merged together from the raw values and the result of getConditions call, where the getConditions values will override those from the raw values.