0
Ich habe eine Post-Methode in meiner Router-Datei, wo ich ein Objekt aus Contact-Modell instanziiert. Aber ich werde für Contact-Modell undefiniert. Der Fehler istnode.js on express kann das Modell nicht finden
Fehler:
**TypeError: Cannot read property 'firstname' of undefined**
Routen/contact.js
var express = require('express');
var router = express.Router();
var Contact = require("../models/contacts");
router.post('/contact', function(req, res, next) {
res.send("POST method");
newContact = new Contact({
firstname: req.body.firstname,
lastname: req.body.lastname
}
models/contacts.js
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var contactSchema = new Schema({
firstname: String,
lastname: String
});
var Contact = module.exports = mongoose.model('Contact', contactSchema);
Danke. Das hat mein Problem gelöst – Sam