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

fluent-schedule

v2.0.1

Published

A human-readable, fluent task scheduling library for Node.js.

Downloads

13

Readme

Fluent Schedule

License: MIT npm version

A human-readable, fluent task scheduling library for Node.js and TypeScript. This library provides a simple API for scheduling tasks without using complex cron syntax.

Features

  • Fluent API: Chain methods to build schedules in a readable way
  • Flexible Scheduling: Support for intervals, specific times, and day-of-week scheduling
  • Type Safety: TypeScript support with full type definitions
  • Error Handling: Clear error messages for invalid configurations
  • Async Support: Jobs can be synchronous or asynchronous functions
  • Non-blocking: Scheduler runs in the background without blocking the event loop
  • Zero Dependencies: Only depends on date-fns for time handling

Installation

Add this to your project:

npm install fluent-schedule

Or with yarn:

yarn add fluent-schedule

Quick Start

Basic Interval Scheduling

import { Job, Scheduler, seconds } from 'fluent-schedule';

// Create a job that runs every 5 seconds
const job = new Job()
  .every(seconds(5))
  .run(() => console.log('Task executed every 5 seconds!'));

// Create and start the scheduler
const scheduler = new Scheduler();
scheduler.add(job);

// This runs in the background (non-blocking)
scheduler.run();

Time-Based Scheduling

import { Job, Scheduler, Weekday } from 'fluent-schedule';

// Create a job that runs at 5:00 PM on weekdays
const job = new Job()
  .onWeekday()
  .at('17:00')
  .run(() => console.log('End of workday!'));

const scheduler = new Scheduler();
scheduler.add(job);

scheduler.run();

Multiple Jobs

import { Job, Scheduler, seconds, Weekday } from 'fluent-schedule';

const job1 = new Job()
  .every(seconds(10))
  .run(() => console.log('Heartbeat every 10 seconds'));

const job2 = new Job()
  .on(Weekday.Monday)
  .at('09:00')
  .run(() => console.log('Monday morning meeting'));

const job3 = new Job()
  .onWeekend()
  .at('10:00')
  .run(() => console.log('Weekend task'));

const scheduler = new Scheduler();
scheduler.add(job1);
scheduler.add(job2);
scheduler.add(job3);

scheduler.run();

Async Tasks

import { Job, Scheduler, minutes } from 'fluent-schedule';

const job = new Job()
  .every(minutes(5))
  .run(async () => {
    const data = await fetch('https://api.example.com/data');
    console.log('Data fetched:', await data.json());
  });

const scheduler = new Scheduler();
scheduler.add(job);
scheduler.run();

API Overview

Job Builder Methods

  • new Job() - Create a new job
  • .every(duration) - Run at fixed intervals (in milliseconds)
  • .at(time_str) - Run at specific time (HH:MM or HH:MM:SS)
  • .on(weekday) - Run on specific days of the week
  • .onWeekday() - Run Monday through Friday
  • .onWeekend() - Run Saturday and Sunday
  • .run(task) - Set the task to execute (can be sync or async)

Time Unit Helpers

The library provides helper functions to convert time units to milliseconds:

import { seconds, minutes, hours } from 'fluent-schedule';

const fiveSeconds = seconds(5);    // 5000
const tenMinutes = minutes(10);    // 600000
const twoHours = hours(2);         // 7200000

Weekday Enum

enum Weekday {
  Sunday = 0,
  Monday = 1,
  Tuesday = 2,
  Wednesday = 3,
  Thursday = 4,
  Friday = 5,
  Saturday = 6
}

Scheduler Methods

  • new Scheduler() - Create a new scheduler
  • .add(job) - Add a configured job (throws error if invalid)
  • .run() - Start the scheduler (non-blocking)
  • .stop() - Stop the scheduler

Error Handling

The library uses typed errors for configuration issues:

import { Job, Scheduler, InvalidTimeFormatError, TaskNotSetError } from 'fluent-schedule';

const invalidJob = new Job().at('99:99').run(() => {});
const scheduler = new Scheduler();

try {
  scheduler.add(invalidJob);
} catch (error) {
  if (error instanceof InvalidTimeFormatError) {
    console.error('Invalid time format:', error.message);
  } else if (error instanceof TaskNotSetError) {
    console.error('Job must have a task set with .run()');
  }
}

Examples

See the examples/ directory for more usage examples:

  • simple.ts - Basic usage with multiple job types

Run an example with TypeScript directly (using tsx):

npx tsx examples/simple.ts

Testing

Run the test suite:

npm test

Run with coverage:

npm test -- --coverage

Documentation

The library is written in TypeScript with full type definitions. Your IDE should provide autocomplete and inline documentation.

For detailed API documentation, refer to the source code or generated TypeDoc documentation.

Performance Considerations

  • The scheduler runs in the background using setTimeout without blocking the event loop
  • Jobs run sequentially in the order they become due
  • Jobs should be lightweight to avoid delaying other scheduled tasks
  • For CPU-intensive tasks, consider using worker threads
  • Async jobs are supported and execute without blocking other jobs
  • The scheduler uses a maximum sleep interval of 1 minute to balance responsiveness and efficiency

Limitations

  • Jobs run sequentially based on their scheduled times
  • No persistence (schedules are lost on process restart)
  • Time precision is limited to milliseconds
  • No support for complex cron-like expressions
  • The scheduler must be explicitly stopped with .stop() to clean up timers

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.

License

This project is licensed under the MIT License - see the LICENSE file for details.