demo

View code
// 引入操作数据库模块(第三方模块)
const mongoose = require('mongoose');

// 数据库连接
mongoose.connect('mongodb://localhost/playground', {
        useNewUrlParser: true,
        useUnifiedTopology: true // 两行解决两个报错问题
    })
    .then(() => console.log('数据库连接成功')) // 连接成功
    .catch(err => console.log(err, '数据库连接失败')); // 连接失败
原文地址:https://www.cnblogs.com/wzos/p/13501063.html