启动mongoose
时间: 2023-11-11 11:58:42 浏览: 124
mongoose的使用
启动mongoose需要先安装mongoose模块,然后在代码中引入mongoose模块并连接数据库。以下是一个简单的示例代码:
```
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/my_database', { useNewUrlParser: true });
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log('Connected to database!');
});
```
阅读全文