3 글 보임 - 1 에서 3 까지 (총 3 중에서)
-
글쓴이글
-
2023년 4월 14일 23:47 #76892
안녕하시오참가자const express = require("express"); const app = express(); const bodyParser = require("body-parser");
let db; const MongoClient = require("mongodb").MongoClient; MongoClient.connect( "mongodb+srv://elielielice:@cluster0.kf70xgg.mongodb.net/?retryWrites=true&w=majority", function (에러, lient) { db = client.db("todoapp");
db.collection("post").insertOne( { 이름: "김", 나이: 20 }, function (에러, 결과) { console.log("저장완료"); } );
app.listen(8080, function () { console.log("listening on 8080"); }); } );
app.get("/", function (요청req2, 응답) { 응답.sendFile(__dirname + "/index.html"); });
app.post("/add", function (요청, 응답) { 응답.send("전송완료"); console.log(요청.body.title); console.log(요청.body.date); }); 이렇게 vscode로 server.js를 작성하고 저장하고 여기서 터미널(파워쉘)을 열었습니다. npm install mongodb@3.6.4는 했습니다. nodemon server.js를 입력하니 오류가 납니다. https://haerim95.tistory.com/50 이 글 보고 해결하려 했는데 그냥 시작 누르고 나오는 터미널에서해봐도 안됩니다 -----밑이 오류 내용-----
(node:18056) Warning: Accessing non-existent property 'MongoError' of module exports inside circular dependency (Use `node --trace-warnings ...` to show where the warning was created) (node:18056) 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. 위 오류들은 무시해도 된다지만 혹시 몰라서 적어봅니다. C:\Users\User\Desktop\AllCoding\codingApple\CA_Js\Node.js\node_modules\mongodb\lib\topologies\replset.js:339 throw err; ^
ReferenceError: client is not defined at C:\Users\User\Desktop\AllCoding\codingApple\CA_Js\Node.js\server.js:13:5 at C:\Users\User\Desktop\AllCoding\codingApple\CA_Js\Node.js\node_modules\mongodb\lib\utils.js:693:5 at C:\Users\User\Desktop\AllCoding\codingApple\CA_Js\Node.js\node_modules\mongodb\lib\core\topologies\replset.js:796:18 at processTicksAndRejections (node:internal/process/task_queues:78:11)[nodemon] app crashed - waiting for file changes before starting...
2023년 4월 15일 09:42 #76950
codingapple키 마스터function (에러, lient) { db = client.db("todoapp"); 에서 client로 바꿉시다
-
글쓴이글
3 글 보임 - 1 에서 3 까지 (총 3 중에서)
- 답변은 로그인 후 가능합니다.