zoukankan      html  css  js  c++  java
  • Node.js学习(3)-用express改写留言本

    安装
    cnpm i -S express
    cnpm i -S express-art-template
    cnpm i -S art-template
     
    var express = require('express')
     
    var app =express()
     
    var comments = [
    {
    name:'zj',
    message:'hello',
    dataTime:'2019-08-14'
    },
    {
    name:'zky',
    message:'hello world',
    dataTime:'2019-08-13'
    },
    ]
    // app.engine() 配置 express-art-template 模板
    app.engine('html', require('express-art-template'));
    // 开放静态资源
    app.use('/public/',express.static('./public'))
     
    app.get('/',function(req,res){
    // res对象本身是没有render方法的,当配置了express-art-template才会给其添加此方法
    res.render('index.html',{
    comments:comments
    })
    })
     
    app.get('/post',function(req,res){
    res.render('post.html',)
    })
     
    app.get('/pinglun',function(req,res){
    var common = req.query;
    common.dateTime = '2019-08-15';
    comments.unshift(common);
    res.redirect('/');
    })
     
    // app.post("/pinglun",(req,res)=>{
    // //post方法获取到了请求参数
    // // console.log(req.body);
    // //req.body.dateTime 添加一个键值对
    // req.body.dateTime="2015-10-16";
    // comments.unshift(req.body);
    // //重定向 参数是重定向的路径
    // res.redirect("/");
    // });
     
    app.listen(3000,function(){
    console.log('running')
    })
  • 相关阅读:
    高地址,低地址:
    大小端
    大小端
    linux下C语言编程解决warning : incompatible implicit declaration of built-in function问题
    给char赋16进制
    go channel 概述
    vue2.x入门学习
    vue-cli安装记录
    maven常用Java配置
    activiti工作流引擎
  • 原文地址:https://www.cnblogs.com/monica4/p/11360003.html
Copyright © 2011-2022 走看看