[Error: Cannot read properties of undefined (reading 'modelName')]

What’s wrong with my code? it looks right and I checked the hint and it looks basically the same.

myApp.js:

require('dotenv').config();
const mongoose = require('mongoose');

const uri = process.env.MONGO_URI;
mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true });

const personSchema = new mongoose.Schema({
  name : { type: String, required: true },
  age : Number,
  favoriteFoods : [String]
});

let Person = mongoose.model('Person', personSchema);
module.exports = Person;

You changed the export.

myApp.js

//----- **DO NOT EDIT BELOW THIS LINE** ----------------------------------

exports.PersonModel = Person;
// rest of exports

server.js

const Person = require("./myApp.js").PersonModel;

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.