• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Node.js, Express 게시판 [nodemon] app crashed - waiting for file changes before starting...

[nodemon] app crashed - waiting for file changes before starting...

3 글 보임 - 1 에서 3 까지 (총 3 중에서)
  • 글쓴이
  • #80747

    양정민
    참가자
    HTML에 DB데이터 꽂아넣는 법 1강의에서 저번시간 숙제 중
    const express = require('express');
    const app = express();
    const bodyParser = require('body-parser');
    app.use(bodyParser.urlencoded({extended : true}));
    const { MongoClient, ServerApiVersion } = require('mongodb');
    const uri = "mongodb+srv://harinworld95:bC7HiRIwJi3Aueap@cluster0.yl5buva.mongodb.net/?retryWrites=true&w=majority";
    const client = new MongoClient(uri, {
    serverApi: {
    version: ServerApiVersion.v1,
    strict: true,
    deprecationErrors: true,
    }
    });
    async function run() {
    try {
    await client.connect();
    await client.db("node-todoapp").collection("post").insertOne({name: 'John', 나이: 20});
    console.log('저장완료');
    } finally {
    await client.close();
    }
    }
    run().catch(console.dir);
    
    
    app.listen(8080, function(){
    console.log('listening on 8080');
    });
    
    
    app.post('/add', (요청, 응답)=>{
    응답.send('전송완료');
    client.db("node-todoapp").collection("post").insertOne({ 제목 : 요청.body.title, 날짜 : 요청.body.date}, (에러, 결과)=>{
    console.log('저장완료');
    });
    })
    
    이렇게 작성하였는데
    [nodemon] app crashed - waiting for file changes before starting...
    
    이러한 에러가 뜹니다.. 어떻게 해야할까요?
    #80748

    양정민
    참가자
    /Users/yangjeongmin/Documents/node.js/todoapp/node_modules/mongodb/lib/operations/execute_operation.js:23
                throw new error_1.MongoNotConnectedError('Client must be connected before running operations');
                      ^
    MongoNotConnectedError: Client must be connected before running operations
        at executeOperationAsync (/Users/yangjeongmin/Documents/node.js/todoapp/node_modules/mongodb/lib/operations/execute_operation.js:23:19)
        at /Users/yangjeongmin/Documents/node.js/todoapp/node_modules/mongodb/lib/operations/execute_operation.js:12:45
        at maybeCallback (/Users/yangjeongmin/Documents/node.js/todoapp/node_modules/mongodb/lib/utils.js:263:21)
        at executeOperation (/Users/yangjeongmin/Documents/node.js/todoapp/node_modules/mongodb/lib/operations/execute_operation.js:12:38)
        at Collection.insertOne (/Users/yangjeongmin/Documents/node.js/todoapp/node_modules/mongodb/lib/collection.js:145:57)
        at /Users/yangjeongmin/Documents/node.js/todoapp/server.js:48:50
        at Layer.handle [as handle_request] (/Users/yangjeongmin/Documents/node.js/todoapp/node_modules/express/lib/router/layer.js:95:5)
        at next (/Users/yangjeongmin/Documents/node.js/todoapp/node_modules/express/lib/router/route.js:144:13)
        at Route.dispatch (/Users/yangjeongmin/Documents/node.js/todoapp/node_modules/express/lib/router/route.js:114:3)
        at Layer.handle [as handle_request] (/Users/yangjeongmin/Documents/node.js/todoapp/node_modules/express/lib/router/layer.js:95:5) {
      [Symbol(errorLabels)]: Set(0) {}
    }
    Node.js v18.12.1
    [nodemon] app crashed - waiting for file changes before starting...
    오류 전문입니다.!
    #80778

    codingapple
    키 마스터
    await client.connect()를 변수에 저장해놓고 변수.collection() 해서 써봅시다
3 글 보임 - 1 에서 3 까지 (총 3 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠