-
글쓴이글
-
2021년 6월 21일 08:46 #10590
지수환참가자PS C:\Users\USER\Desktop\develop\node.js> nodemon server.js
[nodemon] 2.0.7
[nodemon] to restart at any time, enter rs
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting node server.js
(node:28652) Warning: Accessing non-existent property 'MongoError' of module exports inside circular dependency
(Use node --trace-warnings ...to show where the warning was created)
(node:28652) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the
MongoClient constructor.
MongoNetworkError: failed to connect to server [cluster-shard-00-01.s4ls4.mongodb.net:27017] on first connect [MongoNetworkError: connection 5 to cluster-shard-00-01.s4ls4.mongodb.net:27017 closed
at TLSSocket.<anonymous> (C:\Users\USER\Desktop\develop\node.js\node_modules\mongodb\lib\core\connection\connection.js:439:9)
at Object.onceWrapper (events.js:483:26)
at TLSSocket.emit (events.js:376:20)
at net.js:673:12
at TCP.done (_tls_wrap.js:563:7)]
at Pool.<anonymous> (C:\Users\USER\Desktop\develop\node.js\node_modules\mongodb\lib\core\topologies\server.js:438:11)
at Pool.emit (events.js:376:20)
at C:\Users\USER\Desktop\develop\node.js\node_modules\mongodb\lib\core\connection\pool.js:562:14
at C:\Users\USER\Desktop\develop\node.js\node_modules\mongodb\lib\core\connection\pool.js:1009:9
at callback (C:\Users\USER\Desktop\develop\node.js\node_modules\mongodb\lib\core\connection\connect.js:75:5)
at C:\Users\USER\Desktop\develop\node.js\node_modules\mongodb\lib\core\connection\connect.js:101:9
at _callback (C:\Users\USER\Desktop\develop\node.js\node_modules\mongodb\lib\core\connection\connection.js:328:7)
at Connection.errorHandler (C:\Users\USER\Desktop\develop\node.js\node_modules\mongodb\lib\core\connection\connection.js:343:7)
at Object.onceWrapper (events.js:483:26)
at Connection.emit (events.js:376:20)
[nodemon] clean exit - waiting for changes before restart이러고 한동안 작동이 안돼네요. 구글링 겁나해봐도 안돼요 ㅠㅜ
2021년 6월 21일 09:09 #10592
지수환참가자{
"name": "node",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1",
"mongodb": "^3.6.4"
}
}package.json 파일입니다. 여기서 script 부분에 test가 저렇게 바뀌었는데 저게 잘못된건가요?
2021년 6월 21일 09:09 #10593
지수환참가자const express = require('express');
const app = express();
const bodyParser = require('body-parser');
app.use(body-Parser.urlencoded({extended : true}));const MongoClient = require('mongodb').MongoClient;
var db;
MongoClient.connect('mongodb+srv://<username>:jisuhwan941227@cluster.s4ls4.mongodb.net/myFirstDatabase?retryWrites=true&w=majority', {useUnifiedTopology: true}, function(에러, client){if(에러) return console.log(에러)
db = client.db('todoapp');db.collection('post').insertOne( {이름 : 'John', 나이 : 20}, function(에러,결과){
console.log('저장완료');
});app.listen(8080, function(){
console.log('listening on 8080')
});
});app.get('/pet', function(요청, 응답){
응답.send('펫 용품을 쇼핑할 수 있는 페이지입니다.');
});
app.get('/', function(요청, 응답){
응답.sendFile(__dirname + '/index.html');
});
app.get('/write', function(요청, 응답){
응답.sendFile(__dirname + '/write.html');
});app.post('/add', function(요청, 응답){
응답.send('전송완료');
console.log(요청.body.date);
console.log(요청.body.title);
});server.js 파일도 보내드립니다
2021년 6월 21일 10:01 #10597
codingapple키 마스터MongoNetworkError: failed to connect to server 이거는 DB접속 url을 잘못복사붙여넣기 했거나 그 안에 아이디 비번을 잘못 기입했을 경우인듯요
MongoClient.connect(‘mongodb+srv://DB접속아이디:DB접속비번 이렇게 기입해야할걸요
-
글쓴이글
- 답변은 로그인 후 가능합니다.