[英]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
. 每当执行此操作时,都会收到此错误:
TypeError: Token is not a constructor
。
How can I export the model along with other objects? 如何将模型与其他对象一起导出?
When you import your module with 当您导入模块时
const Something = require('./Something'); // contains the file in your question
you will be able to use new
with: 您将可以通过以下方式使用
new
:
const token = new Something.Token()
您应该这样导入令牌:
const { Token } = require("path to token model");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.