最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

node.js+express留言板功能實(shí)現(xiàn)示例

 更新時(shí)間:2021年09月21日 09:07:24   作者:Moshow鄭鍇  
本文介紹基于nodejs+express+art-template的留言板功能。包含列表界面、添加界面和發(fā)送留言功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

留言板

基于nodejs+express+art-template的留言板功能。包含列表界面、添加界面和發(fā)送留言功能。

所需類庫

直接copy以下package.json 然后直接 npm install 或者yarn install 即可。

package.json所需內(nèi)容如下。

{
  "name": "nodejs_message_board",
  "version": "2021.09",
  "private": true,
  "scripts": {
    "start": "node app"
  },
  "dependencies": {
    "art-template": "^4.13.2",
    "debug": "~2.6.9",
    "express": "~4.16.1",
    "express-art-template": "^1.0.1"
  }
}

開源項(xiàng)目

本項(xiàng)目收錄在【Node.js Study】nodejs開源學(xué)習(xí)項(xiàng)目 中的express_message_board 。歡迎大家學(xué)習(xí)和下載。

運(yùn)行效果 localhost ,留言首頁

在這里插入圖片描述localhost/post ,

添加留言頁面

在這里插入圖片描述localhost/say?

name=xxx&message=xxx ,發(fā)送留言并重定向到首頁功能

在這里插入圖片描述 

項(xiàng)目結(jié)構(gòu)

index.html

這是留言列表,也是首頁。根據(jù)傳過來的值渲染列表。

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>留言板</title>
  <link rel="stylesheet" href="/public/css/bootstrap4.css" rel="external nofollow"  rel="external nofollow" >
</head>
<body>
<div class="header container">
  <div class="page-header">
    <h1>留言板 <small>留言列表</small></h1>
    <a class="btn btn-success" href="/post" rel="external nofollow" >發(fā)表留言</a>
  </div>
</div>
<div class="comments container">
  <ul class="list-group">
    {{each comments}}
    <li class="list-group-item">
      {{$value.name}}說:  {{$value.message}}
      <span class="pull-right">{{$value.datetime}}</span>
    </li>
    {{/each}}
  </ul>
</div>
</body>
</html>

post.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>留言板</title>
    <link rel="stylesheet" href="/public/css/bootstrap4.css" rel="external nofollow"  rel="external nofollow" >
</head>
<body>
<div class="header container">
    <div class="page-header">
        <h1><a href="/" rel="external nofollow"  >留言板 <small>添加留言</small></a></h1>
    </div>
</div>
<div class="comments container">
    <form action="/say" method="GET">
        <div class="form-group">
            <label for="name">你的大名</label>
            <input type="text" id="name" name="name" class="form-control" placeholder="請(qǐng)輸入姓名" required minlength="2" maxlength="10">
        </div>
        <div class="form-group">
            <label for="message">留言內(nèi)容</label>
            <textarea id="message" name="message" class="form-control" placeholder="請(qǐng)輸入留言內(nèi)容" cols='30' rows='10' required minlength="5" maxlength="20"></textarea>
        </div>
        <button type="submit" class="btn btn-default">發(fā)表</button>
    </form>
</div>
</body>
</html>

route/index.js

這里是路由器

const express = require('express');
const router = express.Router();


// 模擬首頁留言列表數(shù)據(jù)
var comments= {"comments":[
    {name:"AAA",message:"你用什么編輯器?WebStorem or VSCODE",datetime:"2021-1-1"},
    {name:"BBB",message:"今天天氣真好?釣魚or代碼",datetime:"2021-1-1"},
    {name:"Moshow",message:"zhengkai.blog.csdn.net",datetime:"2021-1-1"},
    {name:"DDD",message:"哈與哈哈與哈哈哈的區(qū)別",datetime:"2021-1-1"},
    {name:"EEE",message:"王守義十三香還是iphone十三香",datetime:"2021-1-1"}
]}

/* by zhengkai.blog.csdn.net - 靜態(tài)路由托管 */
router.get('/', function(req, res, next) {
    res.render('index', comments);
});
router.get('/post', function(req, res, next) {
    res.render('post', comments);
});
router.get('/say', function(req, res, next) {
    console.log(req.query)
    console.log(req.url)
    const comment=req.query;
    comment.datetime='2021-10-01';
    comments.comments.unshift(comment);
    //重定向到首頁,沒有url后綴 localhost
    res.redirect('/');
    //直接渲染首頁,有url后綴 localhost/say?xxxx=xxx
    //res.render('index', comments);
});

module.exports = router;

app.js

這里作為總控制

//加載模塊
const http=require('http');
const fs=require('fs');
const url=require('url');
const template=require('art-template');
const path = require('path');
const express = require('express');
const router = express.Router();
const app = express();


// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'html');
app.engine('html',require('express-art-template'));

app.use('/public',express.static(path.join(__dirname, 'public')));

const indexRouter = require('./routes/index');
app.use('/', indexRouter);


//創(chuàng)建監(jiān)聽對(duì)象
app.listen(80,function(){
  console.log('zhengkai.blog.csdn.net 項(xiàng)目啟動(dòng)成功 http://localhost')
})

到此這篇關(guān)于node.js+express留言板功能實(shí)現(xiàn)示例的文章就介紹到這了,更多相關(guān)node.js express留言板內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • VsCode無法識(shí)別node問題解決過程

    VsCode無法識(shí)別node問題解決過程

    這篇文章主要給大家介紹了關(guān)于VsCode無法識(shí)別node問題解決的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2023-07-07
  • node使用crypto模塊為用戶密碼加密

    node使用crypto模塊為用戶密碼加密

    本文主要介紹了node使用crypto模塊為用戶密碼加密,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-07-07
  • nodejs連接mysql數(shù)據(jù)庫及基本知識(shí)點(diǎn)詳解

    nodejs連接mysql數(shù)據(jù)庫及基本知識(shí)點(diǎn)詳解

    這篇文章主要介紹了nodejs連接mysql數(shù)據(jù)庫,結(jié)合實(shí)例形式總結(jié)分析了nodejs連接與操作mysql數(shù)據(jù)庫的相關(guān)模板、配置及mysql數(shù)據(jù)庫查詢、添加數(shù)據(jù)等操作技巧,需要的朋友可以參考下
    2018-03-03
  • 關(guān)于express與koa的使用對(duì)比詳解

    關(guān)于express與koa的使用對(duì)比詳解

    很多人都在問到底該用Koa還是express,所以下面這篇文章就來給大家再次的對(duì)比了關(guān)于express與koa的相關(guān)資料,通過對(duì)比大家可以更好的進(jìn)行選擇,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-01-01
  • node中的Express框架詳解

    node中的Express框架詳解

    這篇文章主要介紹了node中的Express框架,框架是為了規(guī)范開發(fā)流程,降低開發(fā)難度,提高開發(fā)效率而制定的一套共人們使用的功能模塊或者是編程的約定,需要的朋友可以參考下
    2023-04-04
  • 基于Node.js實(shí)現(xiàn)nodemailer郵件發(fā)送

    基于Node.js實(shí)現(xiàn)nodemailer郵件發(fā)送

    Nodemailer 是一個(gè)簡(jiǎn)單易用的 Node.JS 郵件發(fā)送模塊(通過 SMTP,sendmail,或者 Amazon SES),支持 unicode,你可以使用任何你喜歡的字符集。Nodemailer是一個(gè)簡(jiǎn)單易用的Node.js郵件發(fā)送組件,需要的朋友可以參考下
    2016-01-01
  • node中socket.io的事件使用詳解

    node中socket.io的事件使用詳解

    這篇文章主要介紹了node中socket.io的事件使用詳解,需要的朋友可以參考下
    2014-12-12
  • node.js中g(shù)et和post接口教程

    node.js中g(shù)et和post接口教程

    這篇文章主要介紹了node.js中g(shù)et和post接口學(xué)習(xí),文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-05-05
  • 淺談Node 調(diào)試工具入門教程

    淺談Node 調(diào)試工具入門教程

    這篇文章主要介紹了淺談Node 調(diào)試工具入門教程,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-03-03
  • npm安裝報(bào)錯(cuò)npm ERR! Error: EPERM: operation not permitted解決

    npm安裝報(bào)錯(cuò)npm ERR! Error: EPERM: operation&

    這篇文章主要為大家介紹了npm安裝報(bào)錯(cuò)npm ERR! Error: EPERM: operation not permitted解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07

最新評(píng)論

新泰市| 清流县| 两当县| 兴文县| 凌源市| 兴文县| 文安县| 巩留县| 隆化县| 张家界市| 绿春县| 渝北区| 临朐县| 什邡市| 环江| 奉贤区| 洪湖市| 香格里拉县| 宁国市| 南宁市| 喀喇| 德清县| 尤溪县| 句容市| 永嘉县| 濮阳县| 台山市| 招远市| 永济市| 温泉县| 会宁县| 阿拉尔市| 辽阳市| 三原县| 南岸区| 舞钢市| 金坛市| 昭觉县| 泗阳县| 平南县| 柏乡县|