It seems the code is ok to me, but I get an empty array. Can anyone please help me on this. I watched many tutorials and I can't understand what I'm doing wrong here. Really appreciate your help
DruginformationController.js
var druginformation = require('../models/DruginformationModel');
module.exports = {
get: function (req, res) {
druginformation.find({}).exec(function (err, result) {
res.send(result);
})
}
}
DruginformationModel.js
var mongoose = require('mongoose');
module.exports = mongoose.model('druginformation',{
Category:String,
Type:String,
Name:String,
Price:Number,
Reorderlevel:Number,
Dangerlevel:Number,
Remarks:String
});
server.js
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
app.use(bodyParser.json());
app.use(cors);
var druginformation = require('./controllers/DruginformationController');
app.get('/api/getdruginformation',druginformation.get);
mongoose.Promise = global.Promise;
mongoose.connect("mongodb://root:root@xxxx.mlab.com:xxxx/xx-xx", function (err, db) {
if (!err) {
console.log("we are connected to mongo");
}
})
var server = app.listen(5000, function () {
console.log('listening on port ', server.address().port)
})