UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017

Solution 1:

Take in account that MongoDB should be running before issuing npm run dev.

You have to initialize database engine with mongod command first. Sometimes it's easy to forget this step.

Solution 2:

I think your URL is not properly formatted,

use below URL

mongodb://localhost:27017/{DATABASE_NAME}

Solution 3:

In my case, when I changed "mongodb://localhost:27017" to "mongodb://127.0.0.1:27017", it worked