前端学习(1359) :学生档案信息管理1
生活随笔
收集整理的這篇文章主要介紹了
前端学习(1359) :学生档案信息管理1
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
\
service.js
//引入http模塊 const http = require('http'); //創(chuàng)建網(wǎng)站服務(wù)器 const app = http.createServer(); // require('./connect.js') const Student = require('./user.js') app.on('request', (req, res) => {res.end('ok'); }); app.listen(3000); console.log('服務(wù)器啟動(dòng)成功');user.js
const mongoose = require('mongoose');const studentsSchema = new mongoose.Schema({name: {type: String,required: true,minlength: 2,maxlength: 10},age: {type: Number,min: 10,max: 25},sex: {type: String},email: String,hobbies: [String],collage: String,enterDate: {type: Date,default: Date.now}}); const Student = mongoose.model('Student', studentsSchema);module.exports = Student;connect.js
//鏈接數(shù)據(jù)庫(kù) const mongoose = require('mongoose'); //鏈接數(shù)據(jù)庫(kù) mongoose.connect('mongodb://localhost/playground', { useNewUrlParser: true }).then(() => console.log('數(shù)據(jù)庫(kù)安裝成功')).catch(() => console.log('數(shù)據(jù)庫(kù)鏈接失敗'))?
總結(jié)
以上是生活随笔為你收集整理的前端学习(1359) :学生档案信息管理1的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 前端学习(1363):学生档案信息管理5
- 下一篇: 前端学习(1288):nodejs模块化