2018-11-16 nodejs nodejs 前端 2 评论 字数统计: 337(字) 阅读时长: 1(分)
源文件
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> <h1>{{pageTitle}}</h1> <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'); // 参数是一个middleware app.use(express.static(__dirname +'/public')); //返回html格式 app.get('/',(req,res)=>{ res.send('<h1>Hello world</h1>'); }); //返回json格式 app.get('/fast',(req,res)=>{ res.send('<h1>Hello world</h1>'); }); //返回文件,about.hbs在views文件夹下 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 /打开网址 |
参考:
- 本文链接: https://dreamerjonson.com/2018/11/16/node-16-heroku-deploy/
- 版权声明: 本博客所有文章除特别声明外,均采用 CC BY 4.0 CN协议 许可协议。转载请注明出处!
郑建勋(jonson)区块链工程师 & Web工程师
灾难总是接踵而至,这正是世间的常理。你以为只要哭诉一下,就会有谁来救你吗?如果失败了,就只能说明我不过是如此程度的男人。