Express initial simple configuration

Book management system (realize functions such as adding, deleting, modifying, searching, routing, templates, etc.)

  1. Initialization
    - npm express body-parser art-template express-art-templatedownload dependencies

     /**
      * 图书管理系统(小demo)----入口文件
      */
     const express = require('express');
     const template = require('art-template');
     const bodyParser = require('body-parser');
     const router = require('./router');
     const path = require('path');
     const app = express();
     
     // 设置模板路径
     app.set('views',path.join(__dirname,'views'));
     // 设置模板引擎
     app.set('view engine','art');
     // express兼容art-template模板
     app.engine('art',require('express-art-template'));
     // 挂载参数处理中间件(post)
     // parse application/x-www-form-urlencoded(解析应用程序/ x-www-form-urlencoded)
     // 作用是解析application/x-www-form-urlencoded格式的数据(默认post表单提交的数据)
     app.use(bodyParser.urlencoded({ extended: false }));
     // 解析 application/json 类型的数据(处理json格式的参数)
     app.use(bodyParser.json());
     
     // 启动服务器功能
     // 配置路由
     app.use(router);
     // 监听端口
     app.listen(3000,()=>{
         console.log('running....');
     })
    

Insert picture description here

Specific routing processing, link templates and other methods are on github

Guess you like

Origin blog.csdn.net/weixin_43996999/article/details/103138195