const http = require('http');
const mongoose = require('mongoose');//数据库连接
mongoose.connect('mongodb://localhost/playground', { useUnifiedTopology: true }).then(() => console.log('数据库连接成功')).catch(() => console.log('数据库连接失败'));const userSchema = new mongoose.Schema({name: {type: String,required: true,minlength: 2,maxlength: 20},age: {type: Number,min: 18,max: 80},password: String,email: String,hobbies: [String]
});
const User = mongoose.model('User', userSchema);
//为服务器对象添加请求事件
const app = http.createServer();
app.on('request', (req, res) => {res.end('ok');
})
app.listen(3000);
运行结果