I am having an error with mongoose. This is my code
const { ApolloServer } = require("apollo-server");
const gql = require("graphql-tag");
const mongoose = require("mongoose");
const { MONGODB } = require("./config");
const typeDefs = gql `
type Query {
sayHi: String!
}
`;
const resolvers = {
Query: {
sayHi: () => "Hello from GraphQL",
},
};
const server = new ApolloServer({
typeDefs,
resolvers,
});
mongoose
.connect(MONGODB, {
useNewUrlParser: true,
})
.then(() => {
console.log("Connection to Db established sucessfully!");
return server.listen({
port: 5000,
});
})
.then((res) => {
console.log(`Server running at ${res.url}`);
});
And I am getting this error on bash.
The use of Unhandled Promise Rejection is deprecated. The next time node's will exit with an exit code of non-zero.
Can someone please tell me how to solve it with a code example.
I think the error is in the mongoose.connect(())
line.