from mongoose v5.0.2 to v7 the connect method changed from mongoose.connect(mongodb://localhost… to mongoose.connect(mongodb://127.0.0.1… unless you want to use IPV6 protocol because by default localhost represents 127.0.0.1 for IPV6 not IPV4. If you want to use localhost word then switch to IPV6, because machines are usually set to IPV4 by default