0

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.

  • I hope this will help you. https://stackoverflow.com/questions/44107128/how-to-resolve-unhandledpromiserejectionwarning-in-mongoose/50423423 – Sumit Sep 22 '20 at 16:19
  • When I simulate your code, I get a "not existing property error" for "res.url". It works properly when I replace "url" with an existing property. – salihtopcu Sep 22 '20 at 16:20

0 Answers0