国产精品与欧美交牲久久久久_国产精品毛片在线完整版_成人欧美在线视频_一个人看的www日本高清视频_日韩AV东北熟女_一区二区三区黄色毛片免费高清视频_亚洲欧美另类人妻_四虎精品免费视频_久久国产精品99精品国产_免费看黄片在线看

我們經(jīng)常使用前端的免費空間GitHub,但是后端經(jīng)常聽到的是Heroku云平臺,目前支持以下語言。本文主要介紹Node.js組合MySQL與Git上傳。

Node.js+MySQL部署Heroku云平臺

本篇目錄

環(huán)境建置

注冊

安裝Heroku Cli

登入Heroku云平臺

布署

Git Ignore

建立Git

新增/連接APP

布署Heroku云平臺

MySQL配備

Session Store

報錯處理

環(huán)境建置

注冊

首先,我們先進入官網(wǎng),選擇注冊(Sign up)

填寫姓名、郵件等信息

等候Heroku云平臺將驗證信寄到信箱后,點選連接并連接到輸入密碼

完成

Node.js組合MySQL與Git上傳

安裝Heroku cli

以后我們都要用Heroku cli先附上下載頁面。連接后,根據(jù)您的系統(tǒng)安裝合適的版本。

另外,我們會組合Git上傳專案,Git安裝可參考此處,

關於Git版本控制可參考高見龍大Git教學。

image

為了保證以后的順利運行,我們還需要Node版本8以上npm,您可以使用以下指令查詢是否已安裝。

$node--version

v10.16.1

$npm--version

6.12.0

登入Heroku

在完成上述環(huán)境建設后,您可以在終端上輸入:

$herokulogin

heroku:Press any key to open up the browser to login or q to exit:

Opening browser to https://cli-auth.heroku.com/auth/browser/xxx

Logging in...done

Logged in as xxxxxxxxx@gmail.com

這時會打開Heroku登錄頁面,輸入帳號密碼OK了!

布署

資料夾目前如下:

Git Ignore

在Git上傳前應該做的重大事情。

專案內(nèi)有個node_modules不需要上傳資料,因為他容量大,一般來說Heroku云平臺會自動根據(jù)package.json安裝所需的套件。因此,我們需要先建立它.gitignore文件和新的忽略規(guī)則。


建立Git

再來建立專案Git版本控制:

//進入專用數(shù)據(jù)

$cd chatroom

$git init

$git add.

$git commit -m 'first commit'

新增/連接APP

新增HerokuAPP,后面沒有名字Heroku會自己給與APP隨機名字。

$ heroku create [app-name]

Creating ? thef2e-chatroom...done

https://thef2e-chatroom.herokuapp.com/|

https://git.heroku.com/thef2e-chatroom.git

請注意,如果您想更改項目名稱,請訪問官方網(wǎng)站setting更改他的兩個網(wǎng)站不會改變,所以輸入以下指令更安全!

$herokuapps:rename--app[old-name][new-name]

現(xiàn)在,我們得到了APP網(wǎng)址以及Git數(shù)據(jù)庫網(wǎng)站。我們使用它Heroku將本地專案與遠端聯(lián)系起來:

$herokugit:remote-a[app-name]

//查看

$ git push heroku master

Enumerating objects: 6, done.

Counting objects: 100% (6/6), done.

Delta compression using up to 4 threads

Compressing objects: 100% (6/6), done.

Writing objects: 100% (6/6), 10.87 KiB | 5.44 MiB/s, done.

Total 6 (delta 0), reused 0 (delta 0)

remote: Compressing source files... done.

remote: Building source:

remote:

remote: -----> Node.js app detected

remote:

remote: -----> Creating runtime environment

remote:

remote:        NPM_CONFIG_LOGLEVEL=error

remote:        NODE_ENV=production

remote:        NODE_MODULES_CACHE=true

remote:        NODE_VERBOSE=false

remote:

remote: -----> Installing binaries

remote:        engines.node (package.json):  unspecified

remote:        engines.npm (package.json):   unspecified (use default)

remote:

remote:        Resolving node version 12.x...

remote:        Downloading and installing node 12.13.0...

remote:        Using default npm version: 6.12.0

remote:

remote: -----> Installing dependencies

remote:        Installing node modules (package.json + package-lock)

remote:        added 123 packages from 102 contributors and audited 239 packages in 3.359s

remote:        found 0 vulnerabilities

remote:

remote:

remote: -----> Build

remote:

remote: -----> Pruning devDependencies

remote:        audited 239 packages in 1.408s

remote:        found 0 vulnerabilities

remote:

remote:

remote: -----> Caching build

remote:        - node_modules

remote:

remote: -----> Build succeeded!

remote:  !     This app may not specify any way to start a node process

remote:        https://devcenter.heroku.com/articles/nodejs-support#default-web-process-type

remote:

remote: -----> Discovering process types

remote:        Procfile declares types     -> (none)

remote:        Default types for buildpack -> web

remote:

remote: -----> Compressing...

remote:        Done: 23.1M

remote: -----> Launching...

remote:        Released v3

remote:        https://thef2e-chatroom.herokuapp.com/ deployed to Heroku

remote:

remote: Verifying deploy... done.

To https://git.heroku.com/thef2e-chatroom.git

 * [new branch]      master -> master

如果你按照我的倉庫步驟建立一個項目,你會發(fā)現(xiàn)終端有一行顯示驚嘆號,因為Heroku需要一行Start指示建立專案,我們package.json在報錯之前,檔中沒有明確的指示。

所以我們需要在那里JSON檔內(nèi)多新增一行start,并重新push一次,Heroku環(huán)境建設成功。

"scripts": {  

    "test": "echo \"Error: no test specified\" && exit 1",  

    "start": "node index.js"

},

MySQL配備

然后我們來到第二個價格,準備把當?shù)氐臄?shù)據(jù)庫push上來,這次使用的服務是ClearDB。

我們必須首先增加一個新的項目Add-ons:

$ heroku addons:create cleardb:ignite

Creating cleardb:ignite on ? thef2e-chatroom... free

Created cleardb-octagonal-43734 as CLEARDB_DATABASE_URL

Use heroku addons:docs cleardb to view documentation

還可以在Heroku新網(wǎng)站:

image

通過以下指令,我們可以知道ClearDB數(shù)據(jù)庫配備:

$ heroku config | grep CLEARDB_DATABASE_URL


CLEARDB_DATABASE_URL:mysql://be6c96a165xxx0:c504fxxx@us-cdbr-iron-east-05.cleardb.net/heroku_e8d000339887xxx?reconnect=true

// 補充

// username: be6c96a16xxxd

// password: c504fxxx

// host: us-cdbr-iron-east-05.cleardb.net

// database: heroku_e8d000339887xxx

接著開啟MySQLWorkbench,新的連接可以連接到新的數(shù)據(jù)庫,然后連接到當?shù)囟薲atabase導出,引入遠端數(shù)據(jù)庫OK了!

image

順便說一句,由于遠端數(shù)據(jù)庫的增加,我們原程序碼中連接的本地端數(shù)據(jù)庫也需要更換為遠端數(shù)據(jù)庫!

SessionStore

最后,假如你有介紹Session在項目中,還需要添加一個新的配備特性store,也就是Session存放的地方,在express-sessionnpm下面可以找到很多存儲方法。

image

我們選用express-mysql-session,同樣先安裝:

$ npm install express-mysql-session --save

并引入和使用(設置在Session上方):

const MySQLStore = require('express-mysql-session')(session);


const options = {

  connectionLimit: 10,

  host: 'us-cdbr-iron-east-05.cleardb.net',

  user: 'be6c96a165xxx0',

  password: 'c504fxxx',

  database: 'heroku_e8d000339887xxx'

}

const sessionStore = new MySQLStore(options);


// 此處為 session 設置

app.use(session({

  secret: 'thef2e_chatroom',

  resave: false,

  saveUninitialized: false,

  cookie: {

    maxAge: 60 * 60 * 1000 * 3,

  },

}));

報錯處理

在APP網(wǎng)站右上角可以打開APP(如果你看到這個頁面代表錯誤。


此時可以使用以下指令查詢(使用以下指令)ctrlc撤出):

$ heroku logs --tail


如果你報錯了,多看終端,仔細看肯定會發(fā)現(xiàn)問題!

以上是不讀報錯的最大經(jīng)驗。


www.yinyiprinting.cn 寧波海美seo網(wǎng)絡優(yōu)化公司 是網(wǎng)頁設計制作,網(wǎng)站優(yōu)化,企業(yè)關鍵詞排名,網(wǎng)絡營銷知識和開發(fā)愛好者的一站式目的地,提供豐富的信息、資源和工具來幫助用戶創(chuàng)建令人驚嘆的實用網(wǎng)站。 該平臺致力于提供實用、相關和最新的內(nèi)容,這使其成為初學者和經(jīng)驗豐富的專業(yè)人士的寶貴資源。

點贊(41) 打賞

聲明本文內(nèi)容來自網(wǎng)絡,若涉及侵權,請聯(lián)系我們刪除! 投稿需知:請以word形式發(fā)送至郵箱18067275213@163.com

評論列表 共有 10 條評論

付~~ 1年前 回復TA

當局者迷,旁觀者清,存在競爭,才會進步

小明seo 1年前 回復TA

我的.chapiao.com為什么有時候是4有時候突然變0了,請問這是怎么回事兒?還有百度排名突然下降,我沒有作弊,就是修改了一下網(wǎng)頁,后來我又恢復了,請問多長時間排名才可以上去呢?謝謝指點

輔助線 1年前 回復TA

現(xiàn)在主流又開始慢慢簡單了….這個是實話…

折800 2年前 回復TA

存在即為合理。。。。。。。。。。沒辦法

feng賀興林 2年前 回復TA

書早買了·不過還沒看完。。非常不錯

折疊車 2年前 回復TA

什么意思~

jackly 2年前 回復TA

女兒好可愛呀。。 愿你們幸福!

簽證網(wǎng) 2年前 回復TA

我剛剛在開始這方面的學習,看了文章覺得還是有幫助,可是具體的一些東西太復雜了,還是不能完全弄懂。高手請多賜教賜教,我這網(wǎng)站是做辦公室家具的

china 2年前 回復TA

支持這樣的技術性文章 實踐出真知嘛! 敬佩實踐的精神、分享的精神

wWMm 2年前 回復TA

貌似時間趕得不好,渣浪今日剛巧關閉了評論。

立即
投稿
發(fā)表
評論
返回
頂部