源文件
views/partials/footer.hbs:
1 2 3
| <Header> <footer>{{pageTitle}}</footer> <Header>
|
views/about.hbs:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Some Website</title> </head> <body> <h2>{{pageTitle}}</h2> <p><a href="/">Home</a></p> <p><a href="/about">About</a></p> <p>Some text here</p>
{{> footer}} </body> </html> sx
|
express.js:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| const express = require('express'); const hbs = require('hbs'); const fs = require('fs'); var app = express();
const port = process.env.PORT || 3000;
hbs.registerPartials(__dirname + '/views/partials'); app.set('view engine','hbs');
app.use(express.static(__dirname +'/public'));
app.get('/',(req,res)=>{ res.send('<h2>Hello world</h2>'); });
app.get('/fast',(req,res)=>{ res.send('<h2>Hello world</h2>'); });
app.get('/about',(req,res)=>{ res.render('about.hbs',{ pageTitle:'About Page', currentYear:new Date().getFullYear() }); });
app.listen(port,()=>{ console.log('hello jonson'); });
|
git
1 2 3 4
| .gitignore里面的文件不会提交 git init git add . git commit -m "fitst commit"
|
heroku
安装heroku-cli 略…
1 2 3 4
| heroku login // 登陆账号密码 hexoru create //创建分支 git push heroku master //提交到heroku管理的远程分支 hexoru open /打开网址
|
参考:
heroku部署
heroku监控台
本文链接: https://dreamerjonson.com/2018/11/16/node-16-heroku-deploy/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY 4.0 CN协议 许可协议。转载请注明出处!
