아미(아름다운미소)

Node.js mongodb 드라이버 비동기 / 대기 쿼리 본문

랭귀지/NodeJS

Node.js mongodb 드라이버 비동기 / 대기 쿼리

유키공 2020. 5. 2. 22:30

const { MongoClient } = require('mongodb')    

const MONGO_DB = 'mongodb://localhost:27017'
    let db
    
    try {
        const client = await MongoClient.connect(MONGO_DB, { useNewUrlParser: true })
        db = client.db('nodejsdb')
        console.log("데이타베이스에 연결되었습니다. :" + MONGO_DB);
    } catch (error) {
        console.log(`
            Mongo DB Host not found!
            please add DB_HOST environment variable to .env file
            exiting...
       `)
        process.exit(1)
    }

Comments