Two days of results---node,express,mongodb, and Mongoose's analysis of GitHub's own blog-building projects

Source: Internet
Author: User
Tags tagname git clone

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.