Cov txheej txheem:

Yuav Ua Li Cas Siv Node.js App ntawm Heroku: 3 Cov Kauj Ruam
Yuav Ua Li Cas Siv Node.js App ntawm Heroku: 3 Cov Kauj Ruam

Video: Yuav Ua Li Cas Siv Node.js App ntawm Heroku: 3 Cov Kauj Ruam

Video: Yuav Ua Li Cas Siv Node.js App ntawm Heroku: 3 Cov Kauj Ruam
Video: Tshuaj theem vim li cas thiaj tau nqi ?/ Siv kho mob dab tsi?/paris polyphylla использовать для? 2024, Kaum ib hlis
Anonim
Yuav Ua Li Cas Tso Node.js App ntawm Heroku
Yuav Ua Li Cas Tso Node.js App ntawm Heroku

Nov yog qhov kuv tau siv kuv li NodeJS App ntawm Heroku siv tus as khauj dawb. Tsuas yog nyem qhov txuas mus rub cov software tsim nyog:

Software siv:

VSCode (lossis cov ntawv sau uas koj xaiv)

HerokuCLI

Git

Kauj ruam 1: Tsim Package.json

Taw qhia:

Heroku yog ahosting lub vev xaib uas tso cai rau ypu xa 5 daim ntawv thov pub dawb nrog lub sijhawm ua haujlwm ntawm 500+ teev hauv ib hlis. Txhawm rau xa ib qho, koj yuav tsum xa 3 cov ntaub ntawv:

Ib pob.json thiab pob-lock.json flle. Koj tuaj yeem ua raws kuv lwm qhov kev qhia rau ib qib los ntawm kauj ruam turtorial ntawm kev ua ib qho los ntawm txhaj ntawm no. Pob-lock.json qhia tau pom tom qab lub pob.json tau ua. Txij li thaum peb yuav tau khiav nws ntawm herku, ntawm koj pob, json cov ntaub ntawv koj xav tau kom paub meej qhov pib sau ntawv thiab qhov tseeb ntawm koj cov node ntawm enines. rau tam sim no qhov no khiav cov lus txib ntawm -v. Nov yog qhov piv txwv:

{

"npe": "heroku", "version": "1.0.0", Cov.

"lus piav qhia": "", "lub ntsiab": "index.js", "cov ntawv": {

"test": "ncha \" Yuam kev: tsis muaj qhov ntsuas tshwj xeeb / "&& tawm 1", "pib": "node server.js"

}, "cov ntsiab lus": , "tus sau": "", "daim ntawv tso cai": "ISC", "xyaw": {

"node": "12.x"

}

}

Kauj ruam 2: Tsim Koj Node.js App

Txij li cov app no yuav khiav ntawm txhua qhov chaw nres nkoj heroku muab rau peb, peb yuav tsum txiav txim siab tus lej nws yuav muab rau peb los ntawm kev siv cov cai no.env. PORT. Nov yog lub node js app uas hais tias "nyob zoo":

const http = xav tau ('http'); // thauj cov tsev qiv ntawv los pab nws ua tus servervar chaw nres nkoj = process.env. PORT || 5000; // qhia meej qhov chaw nres nkoj tsis hais dab tsi heroku muab lossis 5000 ntawm tus tswv hauv zos http.createServer (muaj nuj nqi (req, res) {// tsim server server res.writeHead (200, {'Cov ntsiab lus-hom': 'ntawv/dawb')); // Qhia meej tias cov lus teb "nyob zoo" yog cov ntawv res.end ("nyob zoo"); // qhia cov ntawv "nyob zoo" ntawm nplooj ntawv eweb}). Mloog (chaw nres nkoj); // txuas tus neeg rau zaub mov no mus rau chaw nres nkoj tsis.

Kauj ruam 3: Command Prompt

Hais kom sai
Hais kom sai
Hais kom sai
Hais kom sai
Hais kom sai
Hais kom sai
  • Qhib koj cov lus txib tam sim los ntawm nias Windows+R qhib "Khiav" lub thawv tom qab ntawd ntaus "cmd" thiab tom qab ntawv nyem "OK"
  • Ntawm koj CMD, mus rau hauv paus los ntawm kev ntaus "cd.." kom txog thaum tsis muaj txoj hauv kev suav nrog.
  • Txheeb xyuas yog tias npm (tus thawj tswj tsev qiv ntawv teeb tsa los ntawm node), git thiab heroku raug teeb tsa kom raug los ntawm kev ntaus:

npm -rov

git --version heroku --version

Nkag mus rau hauv koj tus account herku

heroku tus ID nkag mus

Qhov no tsim ib qho app ntawm heroku:

heroku tsim

Txhawm rau upload koj cov ntaub ntawv, koj yuav tsum tau mus rau nws txoj hauv kev los ntawm kev ntaus cd

ua cd

Tsim qhov chaw cia khoom tshiab (nplaub tshev) ntawm koj lub cuab yeej hauv zos rau cov khoom hauv txoj kev no

git pib

Txuas nyob deb mus rau daim nplaub tshev ntawm heroku ntawm git ntawm koj li app

heroku git: tej thaj chaw deb

Luam theej tawm cov ntawv no nyob deb rau koj lub zos git repository u ntawm git ntawm koj li app

git ua add.

Txuag qhov kev hloov pauv uas koj tau ua ntawm daim nplaub tshev nrog cov lus ntawm "ua kom nws zoo dua"

git cog lus -am "ua kom nws zoo dua"

Rub tawm cov ntawv mus rau git nplaub tshev ntawm heroku. Tos nws downlaod

git thawb heroku master

qhib lub app

heroku qhib app

Pom zoo: