schoenbl
schoenbl

Reputation: 723

Module.exports with constructor and other objects

I'm trying to do something like this:

let Token = mongoose.model("Token", InToken)

let add = () => {
    return 1 + 1
}

module.exports = {
    Token,
    add
}

Whenever I do this, I receive this error: TypeError: Token is not a constructor.

How can I export the model along with other objects?

Upvotes: 0

Views: 114

Answers (2)

PR7
PR7

Reputation: 1914

You should import Token like this:

const { Token } = require("path to token model");

Upvotes: 0

Federkun
Federkun

Reputation: 36964

When you import your module with

const Something = require('./Something'); // contains the file in your question

you will be able to use new with:

const token = new Something.Token()

Upvotes: 1

Related Questions