I have a node.js model which shown here:
const mongoose = require('mongoose');
const homeSchema =new mongoose.Schema({
_id : mongoose.Schema.Types.ObjectId,
name : String,
address : String,
ownername : String
});
module.exports = mongoose.model('Home', homeSchema);
which I'm using in my route file:
const express = require('express');
const mongoose = require('mongoose');
const HomeSchema = require('../models/home');
const router = express.Router();
router.get('/post',(req,res)=>{
res.status(200).json({message:'Get method'});
});
router.post('/add',(req,res)=>{
const home = new Home({
_id : mongoose.Types.ObjectId(),
name : 'Name',
address : 'Kanter',
ownername : 'data'
});
home.save().then(result=>{
res.status(200).json(result);
});
});
module.exports = router;
But when I'm hitting the API, I'm getting this error:
ReferenceError: Home is not defined