[RESOLVED]到底是用module.export 还是module.exports ?
发布于 7 年前 作者 imbamboo 4007 次浏览 来自 问答

大家好,我有点分不清楚 module.export 跟module.exports的区别 但我发现他们在vscode里是有区别的,例如以下代码

const mongoose = require("mongoose");
const crential = require("../lib/db_credential");
mongoose.connect(crential.connection);

var schema = new mongoose.Schema({
    title: String,
    articleCount: Number,
    createdTime: Date,
    urlName: String,
});

var model = mongoose.model("Category", schema);
module.exports = model;

如果写成 module.exports = model; 我引用的地方,就可以知道model的实例函数,但如果用module.export(没有s),就变成瞎子了。 但在《node与express开发》(web developement with node and express) 是写写成后者(没有s)。 所以他们到底是什么区别,最佳实践是什么?谢谢。

2 回复

哪里有module.export呀?如果有的话那应该就是书中错误了。

@zhanzhenzhen 好吧,闹半天原来是快的印刷错误,难怪google都没有结果。 囧

回到顶部