溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

nodejs漸入佳境[16]-node express項(xiàng)目部署到heroku

發(fā)布時間:2020-06-16 06:49:26 來源:網(wǎng)絡(luò) 閱讀:202 作者:jonson_jackson 欄目:開發(fā)技術(shù)

源文件

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');
// 參數(shù)是一個middleware
app.use(express.static(__dirname +'/public'));
//返回html格式
app.get('/',(req,res)=>{
 res.send('<h2>Hello world</h2>');
});

//返回json格式
app.get('/fast',(req,res)=>{
 res.send('<h2>Hello world</h2>');
});

//返回文件,about.hbs在views文件夾下
app.get('/about',(req,res)=>{
 res.render('about.hbs',{
   pageTitle:'About Page',
   currentYear:new Date().getFullYear()
 });
});
//監(jiān)聽端口,  第二個回調(diào)是開啟服務(wù)器后調(diào)用
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 //創(chuàng)建分支
git push heroku master //提交到heroku管理的遠(yuǎn)程分支
hexoru open   /打開網(wǎng)址

參考:

heroku部署
heroku監(jiān)控臺

  • 本文鏈接: https://dreamerjonson.com/2018/11/16/node-16-heroku-deploy/

  • 版權(quán)聲明: 本博客所有文章除特別聲明外,均采用 CC BY 4.0 CN協(xié)議 許可協(xié)議。轉(zhuǎn)載請注明出處!

nodejs漸入佳境[16]-node express項(xiàng)目部署到heroku

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI