I am trying to extract data using mongoose.
So, every time I had to receive messages from api - localhost: 3000 / api / posts - I get a foll error that I cannot decrypt.
(node: 12100) UnhandledPromiseRejectionWarning: raw promise rejection (r
ejection id: 1): [MongoError: connect ETIMEDOUT xxxx]
The following is my code in api.js. I would appreciate it if you could give recommendations on where I am mistaken.
const express = require('express');
const router = express.Router();
const mongoose = require('mongoose');
const post = require('../models/post');
const db = "mongodb://<dbuser>:<dbpassword>@xxxxxxx.mlab.com:xxxxxx/xxxxxx";
mongoose.Promise = global.Promise;
mongoose.connect(db, function(err) {
if(err) {
console.log('Connection error');
}
});
router.get('/posts', function(req, res) {
console.log('Requesting posts');
post.find({})
.exec(function(err, posts) {
if (err) {
console.log('Error getting the posts');
} else {
res.json(posts);
console.log(posts);
}
});
});
module.exports = router;
May 23, 2017
Now I also get an obsolescence warning when I actually turned on foll loc:
mongoose.Promise = global.Promise; //we add this because if we dont, you may get a warning that mongoose default promise library is deprecated
I would be grateful if I could get some recommendations on this issue. Thanks