Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7634459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:10:50+00:00 2026-05-31T07:10:50+00:00

I’m have a js file that I’m trying to use in a node.js app.

  • 0

I’m have a js file that I’m trying to use in a node.js app. I’ve tried everything I can think of and continue to have issues of either methods not defined or objects not existing.

This is the js file I’m including:

    var $ = require('jquery');

var CountdownTimer = function(options){

  this.settings = $.extend(
            {   
                          seconds: 60,
                          onTick: null,
                          onComplete: null
            },options || {});
};

CountdownTimer.prototype = {

  start: function(){
    this.reset();
    this.interval = window.setInterval($.proxy(this.tick, this), 1000);
  },

  reset: function(){
    if(this.interval){
      clearInterval(this.interval);
    }
    this.secondsRemaining = this.settings.seconds;
    this.tick();

  },

  tick: function(){
    this.hoursRemaining         = Math.floor(this.secondsRemaining / (60 * 60));

    this.minutesRemaining       = this.secondsRemaining % (60 * 60);
    this.hourMinutesRemaining   = Math.floor(this.minutesRemaining / 60);

    this.minuteSecondsRemaining = this.minutesRemaining % 60;
    this.hourSecondsRemaining   = Math.ceil(this.minuteSecondsRemaining);

    this.fHrs = this.formatNumber(this.hoursRemaining);
    this.fMins = this.formatNumber(this.hourMinutesRemaining);
    this.fSecs = this.formatNumber(this.hourSecondsRemaining);

    if(this.settings.onTick){
      console.log(this.settings.onTick);
      this.settings.onTick();
    }
    if(this.secondsRemaining == 0){
      this.complete();
    }
    this.secondsRemaining -= 1;
  },

  complete: function(){
    clearInterval(this.interval);
    if(this.settings.onComplete){
      this.settings.onComplete();
    }
  },

  formatNumber: function(n){
    var s = String(n);
    if(s.length == 1){
      s = '0' + s;
    }
    return s;
  }
}

module.exports = CountdownTimer;

I’m calling it in my app.js like this:

var timer = new require('./countdown.js').CountdownTimer({
    seconds: 80000,
    onTick: function(){
      //do something
    },
    onComplete: function(){
      alert('complete');
    }
  });

timer.start();

The error I’m currently getting is:

TypeError: Object function (options){

this.settings = $.extend( {
seconds: 60,
onTick: null,
onComplete: null },options || {}); } has no method ‘CountdownTimer’

Any ideas what I’m doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:10:51+00:00Added an answer on May 31, 2026 at 7:10 am

    The require system makes an empty module.exports object that you can add properties to, but in your code you are overwriting that with your CountdownTimer function. What you really want to do is add a CountdownTimer property to the module.exports object.

    In other words instead of:

    module.exports = CountdownTimer;
    

    write:

    module.exports.CountdownTimer = CountdownTimer;
    

    Then when you require('./countdown.js'); it’ll return the what you want. Which looks something like this:

    {
        'CountdownTimer': function CountdownTimer() { ... }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.