安裝模板
npm install ejs
var express = require('express'); var app = express(); app.use(express.static('public')); app.set("view engine","ejs"); app.set('views', __dirname + '/views');
創建模板
neo@MacBook-Pro ~/web3.example % mkdir view neo@MacBook-Pro ~/web3.example % vim view/account.ejs
傳遞變數
app.get('/account.html', function (req, res) { var accounts = [ '0xB94054c174995AE2A9E7fcf6c7924635FBa8ECF7', '0xf56b81a2bcb964D2806071e9Be4289A5559BB0fA', '0x997e5CA600E19447D0B82aFBf9c7F00De2B39B16', '0x538b392D57d867A57eE8Eed05737cB08B4691302' ]; res.render("account",{"accounts":accounts}); })
res.render("模板檔案",{"key":value});