前端学习(1360) :学生档案信息管理2
生活随笔
收集整理的這篇文章主要介紹了
前端学习(1360) :学生档案信息管理2
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
service.js
//引入http模塊 const http = require('http'); //創(chuàng)建網(wǎng)站服務(wù)器 const app = http.createServer(); //引入路由 const getRouter = require('router');const router = getRouter();router.get('/test', (req, res) => {res.end('test') }) router.get('/index', (req, res) => {res.end('index') }) require('./connect.js') const Student = require('./user.js') app.on('request', (req, res) => {router(req, res, () => {console.log('1');}) }); 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ù)庫 const mongoose = require('mongoose'); //鏈接數(shù)據(jù)庫 mongoose.connect('mongodb://localhost/playground', { useNewUrlParser: true }).then(() => console.log('數(shù)據(jù)庫安裝成功')).catch(() => console.log('數(shù)據(jù)庫鏈接失敗'))運(yùn)行結(jié)果
總結(jié)
以上是生活随笔為你收集整理的前端学习(1360) :学生档案信息管理2的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: h5 缓存机制
- 下一篇: 前端学习(792):返回索引号