」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 使用 .EJS 範本配置 Express

使用 .EJS 範本配置 Express

發佈於2024-11-08
瀏覽:511

CONFIGURE EXPRESS WITH .EJS TEMPLATE

通常,我使用經典的入門版。
Expressjs.com

const express = require('express')
const app = express()
const port = 3000

app.set('view engine', 'ejs')
app.use(express.urlencoded({extended: true}))
app.use('/', router)
app.listen(port, () => {
    console.log(`This is ${port}`)})

當您使用 res.render('anyClassViewName') 時,Express 將在您的視圖目錄中搜尋任何 .ejs 文件,然後渲染它。

Express.urlencoded 用於處理 urlencoded 有效負載。您可以使用 { Extended: true } 選項來處理任何複雜的對象、陣列和巢狀對象,也可以將其設為「false」以進行更簡單的資料解析。

版本聲明 本文轉載於:https://dev.to/hopelesscoder/configure-express-with-ejs-template-1ach?1如有侵犯,請聯絡[email protected]刪除
最新教學 更多>

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3