
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.
node-timers
Advanced tools
Quick and simple timer utilities that give you enough control.
Get it:
npm install node-timers
Use it:
var node-timers = require('node-timers'); //or
var simpleTimer = require('node-timers/simple'); //or
var timer = require('node-timers/timer'); //or
var countdown = require('node-timers/countdown');
var myTimer = node-timers.simple(); // timer or countdown can be created from here too...
// passing an options object with the pollInterval will generate a 'poll' event ever X milliseconds
// passing no such pollInterval value will create a timer that can be controlled (start, stop, reset)
// but will not ping you with updates.
var simple = simpleTimer({pollInterval: 100});
//Starts keeping track of passed time...
simple.start();
//returns the time that has passed in milliseconds
simple.time();
I seemed to be rewriting this stuff on a regular occasion for different projects. Either misplacing the source or using the modules in a slightly different way. This set gives me enough leway to do what I want without controlling the output like other timer modules I have looked at. The output should be up to the app.
Creates a new simple timer. Keeps track of time passed. Options are optional.
Options can include pollInterval
which, while the timer is on an on
state,
will emit a poll
event with the current passed time in milliseconds.
Starts the timer you have created. Emits a start
event
Stops the timer. Emits a stop
event
Getter and setter for the passed time of your timer. If you specifiy a newTime
value,
then the timer will attempt to set itself to that new value before returning the passed time in milliseconds.
Resets your timer back to it's initial state. Emits a reset
event
Returns the current state of the timer. Either on
, stopped
, or clean
A limited timer based on simple
. Additional options to pollInterval
include finishTime
.
When the timer has reached the finish time stated, it will emit a done
event.
pollInterval
defaults to 250 and finishTime defaults to 0.
A timer that counts down from a startTime
passed though the options object. In this case, time()
returns
the time remaining instead of the time passed. Once the timer reaches 0, it will emit a done
event.
Event | Description |
---|---|
start | Event triggered when timer starts. |
stop | Triggered when the timer stops. |
reset | Timer has been reset. |
poll | Update the user with the currently passed time or time that is left. time is passed as argument to the listener |
done | Only timer and countdown emit this. When we have reached the given endtime or 0 |
FAQs
Timer and stopwatch utility modules
The npm package node-timers receives a total of 18 weekly downloads. As such, node-timers popularity was classified as not popular.
We found that node-timers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.