These are chat archives for Automattic/mongoose

21st
Nov 2016
Nguyễn Hoài Nam
@Vietprogrammer_twitter
Nov 21 2016 16:18

hi everyone, I'm a new on mongoose, I have an issue in very simple example, I have a error: "Webpart is not defined" when call api "/api/webparts"
*/models/webpart.js

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var config = require("./../config/database");
mongoose.connect(config.connectionstring);

var webpartSchema = new Schema({
    name: {
        type: String,
        unique: true,
        require: true
    },
    title: {
        type: String,
        require: true
    },
    description: String,
    settingName: {
        type: String,
        require: true
    }
});


module.exports = mongoose.model('webpart', webpartSchema);

*/routers/webparts.js

var express = require('express');
var router = express.Router();
var WebPart = require('./../models/webpart');

router.get('/', function (req, res, next) {
    Webpart.find(function (err, bears) {
        if (err)
            res.send(err);

        res.json(bears);
    });
});

module.exports = router;

server.js

//...
var webparts = require("./routers/webparts");
app.use('/api/webparts/', webparts);
module.exports = app;
//...
Listu
@Listu
Nov 21 2016 23:08
@Vietprogrammer_twitter why don't you just require('../models/webpart') in your routers/webparts.js ?