Currently, I am in the process of learning Node JS, Mongodb, and Express JS. My goal was to create a database using Mongodb Compass and store some data within it. However, every time I attempt to run my code, my nodemon server crashes after a few minutes of starting.
Below are the main files containing the code:
app.js -
(code snippet here...)
user.js -
(code snippet here...)
index.js -
(code snippet here...)
The purpose behind writing this code was to set up a database for learning and practice. When I run the code on localhost:3000 with the "npx nodemon" command, everything works fine until reaching the index file of the website. However, upon attempting to access the /create route via the URL "localhost:3000/create," the server hangs for a few seconds before crashing. The error message displayed in my terminal reads:
MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 (attempted solution instructions...) Node.js v20.5.1 [nodemon] app crashed - waiting for file changes before starting...
I also tried accessing Mongodb Compass to investigate the issue further. Upon trying to connect to the database, I encountered the following error - connect ECONNREFUSED 127.0.0.1:27017
If anyone could assist me by identifying the cause of this problem and providing a solution, I would greatly appreciate it.