Dead simple count down or count up timer for node and in browser using clientmodules or browserify.
For a standalone version that bundles required modules just use
This isn't meant to be scientifically amazingly perfect. Because we're just looping and comparing with a start time at a set interval. This approach is a bit flawed because it's impacted by the event loop, etc. But it's good enough for the vast majority of regular web app uses.
npm install time-counter
// creating a count up timervar Timer =log = consolelog;var countUpTimer = ;// log out time, could also be used to// write to DOM of course.countUpTimer;// start itcountUpTimerstart;// creating a countdown timervar countDown =direction: 'down'startValue: '1:00' // one minute;// log it out every time it's updatedcountDown;countDown;
Default values shown:
direction: 'up' // can also be 'down'startValue: 0 // starting point, useful for 'down' but works for up tootargetValue: '' // i.e. "1:00:00" is one hour, shoudl be in format: hours:minutes:secondsinterval: 50 // how fast to run the loop and determine if the time has changedshowHours: false // whether or not to show hours if they're empty
To build bundled version run
node build at project root.