몽고db 연결 오류가 납니다 위에껀 입력한 코드, 아래껀 터미널이에요
243
6 asked
const express = require('express')
const app = express()
const port = 5000
const mongoose = require('mongoose')
mongoose.connect('mongodb+srv://newlifecode:1234@newlifecode.f0tau.mongodb.net/test?retryWrites=true&w=majority&appName=newlifecode'
, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log('MongoDB Connected...'))
.catch(err => console.error('MongoDB Connection Error:', err.message));
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
PS C:\Users\USER\Documents\boiler-plate> npm run start
> boiler-plate@1.0.0 start
> node index.js
(node:7628) [MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
(Use `node --trace-warnings ...` to show where the warning was created)
(node:7628) [MONGODB DRIVER] Warning: useUnifiedTopology is a deprecated option: useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
node:events:496
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::5000
at Server.setupListenHandle [as _listen2] (node:net:1907:16)
at listenInCluster (node:net:1964:12)
at Server.listen (node:net:2066:7)
at Function.listen (C:\Users\USER\Documents\boiler-plate\node_modules\express\lib\application.js:635:24)
at Object.<anonymous> (C:\Users\USER\Documents\boiler-plate\index.js:19:5)
at Module._compile (node:internal/modules/cjs/loader:1546:14)
at Object..js (node:internal/modules/cjs/loader:1689:10)
at Module.load (node:internal/modules/cjs/loader:1318:32)
at Function._load (node:internal/modules/cjs/loader:1128:12)
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1943:8)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
code: 'EADDRINUSE',
errno: -4091,
syscall: 'listen',
address: '::',
port: 5000
}
Node.js v22.11.0
PS C:\Users\USER\Documents\boiler-plate> npm run start
> boiler-plate@1.0.0 start
> node index.js
(node:860) [MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
(Use `node --trace-warnings ...` to show where the warning was created)
(node:860) [MONGODB DRIVER] Warning: useUnifiedTopology is a deprecated option: useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
node:events:496
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::5000
at Server.setupListenHandle [as _listen2] (node:net:1907:16)
at listenInCluster (node:net:1964:12)
at Server.listen (node:net:2066:7)
at Function.listen (C:\Users\USER\Documents\boiler-plate\node_modules\express\lib\application.js:635:24)
at Object.<anonymous> (C:\Users\USER\Documents\boiler-plate\index.js:19:5)
at Module._compile (node:internal/modules/cjs/loader:1546:14)
at Object..js (node:internal/modules/cjs/loader:1689:10)
at Module.load (node:internal/modules/cjs/loader:1318:32)
at Function._load (node:internal/modules/cjs/loader:1128:12)
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1943:8)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
code: 'EADDRINUSE',
errno: -4091,
syscall: 'listen',
address: '::',
port: 5000
}
Answer 1
0
안녕하세요, 인프런 AI 인턴입니다. dbwls204605님, 질문해주신 내용을 확인해봤습니다.
현재 발생하고 있는 에러는 두 가지입니다:
포트 충돌 에러 (EADDRINUSE):
Error: listen EADDRINUSE: address already in use :::5000메시지에서 알 수 있듯이, 5000번 포트가 이미 사용 중인 상태입니다. 이 문제는 동일한 포트를 사용하는 다른 프로세스가 있어서 발생합니다.- 해결 방법:
- 터미널에서 포트를 점유 중인 프로세스를 확인하고 종료하세요. 윈도우에서는
netstat -ano | findStr :5000명령어로 확인 후taskkill /PID <pid> /F명령어로 프로세스를 종료할 수 있습니다.
- 또는 서버에서 포트를 변경해서 사용해보세요. 예를 들어,
const port = 5000을const port = 3000등으로 바꿔보세요.
- 터미널에서 포트를 점유 중인 프로세스를 확인하고 종료하세요. 윈도우에서는
- 해결 방법:
MongoDB 드라이버 경고:
useNewUrlParser와useUnifiedTopology옵션이 더 이상 필요하지 않다는 경고입니다. Node.js 드라이버 버전 4.0.0 이후부터는 이 옵션들이 필요하지 않습니다. 경고 메시지이기 때문에 기능에는 영향이 없지만, 코드를 깔끔하게 유지하고 싶다면 제거해도 됩니다.- 코드 수정:
mongoose.connect('mongodb+srv://...', { // 위 옵션들을 제거해주세요 })
- 코드 수정:
관련하여 추가로 확인하실 수 있는 링크를 첨부 드립니다:
저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다. 현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏 추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.
깃 이메일이랑 비번이 필요하다고 하네요
0
35
1
404 에러
0
102
1
34강 인증 체크에서 element 사용 때문에 에러나시는 분들 이렇게 하심 됩니다.
0
119
1
로그인, 로그아웃, 토근 작동 안 함
0
239
0
로그아웃 findOneAndUpdate 함수
0
170
1
9강 오류 어떻게 해결하나요?
0
194
1
localhost 에서 연결을 거부했습니다.
0
1927
4
포스트맨에서 true가 안떠요
0
150
1
왜 안되나요
0
129
1
로그아웃 401 에러(Unauthorized)
0
504
2
암호가 해싱되지 않고 입력값 그대로 db에 저장되는 문제
0
149
1
7강중에서
0
162
2
User.findByToken is not a function
0
211
1
루트 디렉토리
0
271
1
useState
0
560
1
프록시 잘 설정했는데도 404 오류 뜨는 분들
5
875
6
webpack 관련 에러 질문
0
219
1
리액트 관련 질문
0
272
1
14강 로그아웃 안됨
0
318
1
mongoDB 데이터 확인하는 법
0
410
1
postman 에러
0
291
1
선생님 리덕스를 사용하면 어떠한 부분이 좋은지 알 수 있을까요?
0
234
1
다음과 같은 에러들이 발생합니다.
0
273
1
14강 로그아웃 기능 구현시 postman에서 Cannot POST 오류가 뜹니다.
0
379
1

