The Mongo project is initialized first

Then install each required module (

NPM install Mongoose;

NPM Install Express

)

Start command of mongo project: node index

<! Var mongo = require("mongoose"); <! --> mongo.connect('mongodb://localhost:27017/kangxp'.function(err){
  if(err){
    console.log(err)
  }
  else{
    console.log('Database connection successful')}}); module.exports=mongo; // You can export it to use in other filesCopy the code
<! Var express = require('express')
var web = express()
var mongo = require('mongoose')
web.use(express.static('public'))
var mongo = require('./mongo.js');
Copy the code
<! Var lunboobj = new mongo.schema ({id: Number, path: String, app: Object}) var Lunbo = mongo.model('lunbotab', lunboobj)
Copy the code
<! // var fs =require("fs");
// fs.readFile("./bin/bannerlunbo.json".function(err,data){
//   var result = JSON.parse(data.toString())
//   for(var index=0; index<result.data.length; index++){ // var info = result.data[index]; // var lunbolist = new Lunbo(info); // lunbolist.save(function(err){
//       if(err){
//       console.log('Storage failed') / / / /}else{
//         console.log('Saved successfully') //} //}) //} //});Copy the code
<! -- Interface access -->function find() {
  Lunbo.find(function (err, content) {
    web.get('/seninfo'.function (req, res) {
      res.json({
        data: content
      })
    })
    // console.log(content,err)
  })

Copy the code