작성
·
16
0
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
}
답변 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://...', {
// 위 옵션들을 제거해주세요
})
관련하여 추가로 확인하실 수 있는 링크를 첨부 드립니다:
저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다. 현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏 추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.