GitHub Address: Https://github.com/linguowei/myblog
Clone the project Git down;
Analysis:
# git clone https://github.com/linguowei/myblog.git# cd myblog# npm install# npm run build# CD admin # NPM Run build#. CD.. /# node app.js# localhost:7000# localhost:7000/admin
Run the code;
Install dependent packages here, as well as package build background projects and foreground projects
# node app for running services
App.js
Which is connected to the data:
App.use (Router)
Database connection + set up various tables; db.js
Set up separately: Account form;
Article table;
Label table;
Personal Information Form;
varMongoose = require (' Mongoose ')) Mongoose. Promise= Require (' Bluebird ')//mongoose.connect (' Mongodb://wei1:[email protected]:61018/weiwei ')Mongoose.connect (' Mongodb://localhost:27017/weiweiblog ')varUserschema =NewMongoose. Schema ({name:string, pwd:string,})varArticleschema =NewMongoose. Schema ({title:string, date:date, articlecontent:string, state:string, Label:string,})varTagschema =NewMongoose. Schema ({tagname:string, Tagnumber:number,})varPersonalinformationschema =NewMongoose. Schema ({name:string, individualitysignature:string, Introduce:string,})varModels ={User:mongoose.model (' User ', Userschema), Article:mongoose.model (' Article ', Articleschema), TagList:mongoose.model (' TagList ', Tagschema), PersonalInformation:mongoose.model (' Personalinformation ', Personalinformationschema),}module.exports= Models
Create articles, tags, and blog descriptions in Localhost:7000/admin;
The actual background operation:
Start Data debugging
Cd/usr/local/mongodb/binsudo. /mongo
View Articles's Articles
View Tags
Vue to Node,moogooes, MongoDB's request process
Here, I'll take the save tag.
The front-end sends the requested code:
Web page specific occurrence of requests;
Node+mongoose the processing and operation of the data;
Data processing in the background;
//article label save RouteRouter.post ('/api/savearticlelabel ',function(req, res) {db. Taglist.find ({},function(Err, docs) {if(ERR)return; varIsexist =false; //the data is traversed;Docs.foreach (function(item) {if(Item.tagname = =req.body.tagList.tagName) {Isexist=true; } }) //exists without processing and returns an error if(isexist) {Res.json ({error:true, msg: ' Tag already exists '}) }Else{ //Save to database NewDb. TagList (req.body.tagList). Save (function(Error) {if(Error) {Res.send (' Save Failed '); return} res.send ()})
Res.json ({success:true, msg: ' Save succeeded '})
} }) });
The specific use of the process is this, the actual use of more APIs, please view mongoose/express's documentation for use;
Two days of results---node,express,mongodb, and Mongoose's analysis of GitHub's own blog-building projects