typescript-express-starter
typescript-express-starter copied to clipboard
Node 17 causes app to crash due to connection error for Mongoose
Hi there,
This is a minor issue that has a solution posted below.
Describe the Bug (λ²κ·Έ μ€λͺ )
I used the mongoose template and it would start up the server but crashed within 20 secs.
And no error message is shown on the terminal.
After looking into the log, it shows:
2022-04-12 02:19:48 error: uncaughtException: connect ECONNREFUSED ::1:27017 MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
Version to Reproduce (νμ¬ μ¬μ©ν λ²μ )
Steps to Reproduce (μ¬ν μμ)
- nvm use 17 or use node version 17
- npx typescript-express-starter test
- choose mongoose
- cd test
- npm run dev
- App crash
Expected Behavior (μμ λμ)
Server start without crashing
Actual Behavior (μ€μ λμ)
Server crashes within 20 secs,
logs 2022-04-12 02:19:48 error: uncaughtException: connect ECONNREFUSED ::1:27017 MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
Additional Context (μΆκ° μ¬ν)
Confirmed that node 17 is the cause of this. Here is the thread I found about this: https://www.mongodb.com/community/forums/t/mongooseserverselectionerror-connect-econnrefused-127-0-0-1-27017/123421
I tested and confirmed:
- Node 16.14.2 works without issue
- Node 17.8.0 caused the issue
- Changing
DB_HOST = localhost
toDB_HOST = 127.0.0.1
in .env.development.local worked for Node 17.8.0
Capture screen (μΊ‘μ³ νλ©΄)
As in the issue https://github.com/ljlm0402/typescript-express-starter/issues/117, another solution is that try to change the DB_HOST
variable to mongo
in the configuration file .env.development.local