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

  • SEARCH
  • Home
  • 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 8355957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:01:33+00:00 2026-06-09T10:01:33+00:00

I followed this example: Coffeescript and node.js confusion. require instantiates class? , but it

  • 0

I followed this example: Coffeescript and node.js confusion. require instantiates class?, but it doesn’t seem to work – the error is TypeError: undefined is not a function, so I must be doing something wrong. I have a simple coffee-script executable. Here are my steps:

Create a folder structure:

appmq

  • my_executable

  • my_class.coffee

  • package.json

The file contents:

package.json:

{
    "name": "appmq",
    "version": "0.0.1",
    "description": "xxxxxx",
    "repository": "",
    "author": "Frank LoVecchio",
    "dependencies": {
    },
    "bin": {"appmq": "./my_executable"}
}

my_executable:

#!/usr/bin/env coffee
{CommandLineTools} = require './my_class'
cmdTools = new CommandLineTools()

cmdTools.debug()

my_class:

class CommandLineTools

  debug: () ->
    console.log('Version: ' + process.version)
    console.log('Platform: ' + process.platform)
    console.log('Architecture: ' + process.arch)
    console.log('NODE_PATH: ' + process.env.NODE_PATH)

module.exports = CommandLineTools

I then install the application via:

sudo npm install -g

Then I run the application (which produces the error I noted above):

appmq

  • 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-06-09T10:01:35+00:00Added an answer on June 9, 2026 at 10:01 am

    Chris is right in his answer, but it’s got nothing to do with whether you have an explicit constructor in your class but rather what you are exporting.

    If you want to export a single class like this:

    module.exports = CommandLineTools
    

    Then, when you require, what is returned will be what you assigned to module.exports above, i.e.:

    CommandLineTools = require './my_class'
    

    And this will work. What you are doing, is exporting in the manner described above, but you are using CoffeeScript’s destructuring assignment:

    {CommandLineTools} = require './my_class'
    

    which compiles to the js:

    var CommandLineTools;
    CommandLineTools = require('./my_class').CommandLineTools;
    

    Which fails, because the require call will not return an object with the property CommandLineTools, but rather CommandLineTools itself. Now, if you wanted to use the destructuring assigment above, you would have to export CommandLineTools like this:

    exports.CommandLineTools = CommandLineTools
    

    I hope this will shed some light on the matter. Otherwise, ask away in the comments!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I followed this example and it works great but I'm wondering if I can
I've followed this example: RCP+JavaWS but the app just briefly comes up and goes
I appear to have followed this example (found under Defining Your Own Event Class)
According to the example in this website , I followed the steps, but I
Followed this question about delayed_job and monit Its working on my development machine. But
I followed this tutorial . But whenever I try to log in with my
I followed this link to gzip my php driven website It's working fine but
I've just followed this example from Wordpress and I have successfully added an extra
I have been trying to register 3 hotkeys. I followed this example (or this
I've followed this gist , this blog post and downloaded and deployed this example

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.