I'm trying to wrap various MongoDB methods in a Promise wrapper for a Node.js server but I'm getting a
TypeError: Promise is not a constructor
All the code inside the new Promise constructor wrapper works just fine on its own but I need it inside an asynchronous Promise in order to call it from another place.
const MongoClient = require("mongodb").MongoClient;
const Promise = require("promise");
const mongoURL = "...";
function checkURL (domain, path) {
return new Promise(function (resolve, reject) {
const client = new MongoClient(mongoURL, { useNewUrlParser: true });
client.connect()
.then(db => {
const collection = client.db("websites").collection("cool_websites");
return collection.find({domain: domain, path: path}).toArray();
})
.then(result => {
resolve(result);
client.close();
})
})
}
console.log(checkURL("www.stackoverflow.com", "/"));
I expect a console.log of
[ { _id: 123abc,
domain: 'www.stackoverflow.com',
path: '/questions/',
cool_website: true } ]
but in the terminal, I just recieve:
TypeError: Promise is not a constructor