猫鼬-找不到模块'./models/Question'

时间:2018-12-12 02:17:55

标签: node.js mongodb mongoose

我正试图摆脱猫鼬的困扰,但遇到了一些麻烦。我已经实现了这样的模型:

var mongoose = require('mongoose');
const Schema = mongoose.Schema;

    var QuestionSchema = new mongoose.Schema({
      author: {
        type: String,
        required: [true, 'Author is required']
      },
      headline: String,
      description: String,
      answers: [
        { type: Schema.Types.ObjectId,
          ref: 'Answer'
        }
      ],
      createdAt: { 
        type: Date, 
        default: Date.now 
      }
    }, {timestamps: true});

    module.exports = mongoose.model('Question', QuestionSchema);

我尝试在app.js中要求它:

const Question = require('./models/Question');

但是尝试运行Error: Cannot find module './models/Question'时得到node app.js

关于我为什么要得到这个的任何想法吗?

0 个答案:

没有答案