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 🙏

© 2025 – Pkg Stats / Ryan Hefner

eternal-timer

v1.4.2

Published

timer for node.js package

Readme

eternal-timer

A simple and persistent timer library for Node.js. Timers are saved to a file and maintain their state even after process restart.

Features

  • Monitor Timers (asynchronous): Start monitoring expired timers asynchronously; the function returns immediately and the callback is invoked when timers expire.
  • Persistence: Save timer data to a file that persists across process restarts

Installation

npm install eternal-timer

Usage

Basic Example

import { createTimer, checkTimers, removeTimer, showTimers } from 'eternal-timer';

async function main() {
  // Create a timer (5 seconds)
  const timerId = await createTimer(5000);
  console.log('Timer created:', timerId);

  // Monitor timers (executes when timer expires)
  checkTimers((timer) => {
    console.log('Timer expired:', timer.id);
  });

  // Display all timers
  const timers = await showTimers();
  console.log('Active timers:', timers);

  // Remove a timer
  await removeTimer(timerId);
}

API

createTimer(length: number): Promise<string>

Creates a new timer.

Parameters:

  • length (number): Timer duration in milliseconds

Returns: Promise that resolves to the timer ID (UUID)

Throws: If length is invalid(e.g. length < 0) or file operation fails

removeTimer(id: string): Promise<boolean>

Removes a timer by ID.

Parameters:

  • id (string): ID of the timer to remove

Returns: void

checkTimers(callback: (timer: Timer) => void, interval?: number): Promise<void>

Starts monitoring expired timers asynchronously and returns immediately. The callback is invoked asynchronously when a timer expires.

Parameters:

  • callback: Function invoked when an expired timer is detected (called asynchronously)
  • interval (number, optional): Check interval in milliseconds (default: 50ms)

Throws: If file operation fails

showTimers(): Promise<Timer[]>

Retrieves all active timers.

Returns: Array of Timer objects

Throws: If file operation fails

Type Definition

type Timer = {
    id: string;      // Unique timer identifier (UUID)
    start: string;   // Timer start timestamp
    stop: string;    // Timer end timestamp
}

Scripts

  • npm run dev: Run in development mode with nodemon
  • npm run build: Compile TypeScript
  • npm start: Run compiled JavaScript

Storage

Timer data is stored in the .timers file in the project root. Each line follows this format:

{id} {start_timestamp} {stop_timestamp}

License

Apache-2.0

Licensed under the Apache License, Version 2.0. See the LICENSE file for details.

Repository

https://github.com/SUKEsann2000/eternal-timer