require function giving error when loading module from models

141 views Asked by At

I am using MEAN stack, I have a file project.js in models directory and it contains schema for my nosql. I am trying to use that module in my controller file Project.js but I am getting error on this:

const Pro = require('../models/project')

When I comment this line code works but again its not mapped and not saving the data in my MongoDB.

My project.js is below

const mongoose = require('mongoose')

var projSchema = new.mongoose.Schema(
    {
        name:
        {
            type: String,
            required = true
        },
        dueDate:
        {
            type:Date
        },
        course:
        {
            type: String,
            required = true
        }
    })

module.exports= mongoose.model('Pro',projSchema);

Error:

internal/modules/cjs/loader.js:888
  throw err;
  ^

Error: Cannot find module 'C:Program Files
odejsExpressTracker2models'
1

There are 1 answers

1
majid On BEST ANSWER
var projSchema = **new.mongoose**.Schema(

one typo is here

var projSchema = new mongoose.Schema(

or

maybe your problem in importing and exporting model

mongoose.model('Pro',projSchema);
//importing
const Pro = mongoose.model('Pro')

or

const Pro = mongoose.model('Pro',projSchema);
module.exports=Pro

const Pro=require(../address)