typescript-express-starter icon indicating copy to clipboard operation
typescript-express-starter copied to clipboard

Node 17 causes app to crash due to connection error for Mongoose

Open julschong opened this issue 2 years ago β€’ 2 comments

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 (ν˜„μž¬ μ‚¬μš©ν•œ 버전)

[email protected]

Steps to Reproduce (μž¬ν˜„ μˆœμ„œ)

  1. nvm use 17 or use node version 17
  2. npx typescript-express-starter test
  3. choose mongoose
  4. cd test
  5. npm run dev
  6. 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 to DB_HOST = 127.0.0.1 in .env.development.local worked for Node 17.8.0

Capture screen (캑쳐 ν™”λ©΄)

image

julschong avatar Apr 12 '22 10:04 julschong

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

main95 avatar May 11 '22 08:05 main95