react部署在node_如何在沒有命令行的情況下在3分鐘內將React + Node應用程序部署到Heroku

react部署在node

In this tutorial we will be doing a basic React + Node app deploy to Heroku.

在本教程中,我們將進行基本的React + Node應用程序部署到Heroku。

There are a lot of tutorials that do this only using the command line, so to change things up a bit, I will do it completely without the command line.

有很多教程僅使用命令行來執行此操作,因此,要稍微改變一下內容,我將完全不用命令行來執行此操作。

For things like generating React and Express apps, we have no choice but to use the command line. For everything else we'll use a GUI.

對于生成React和Express應用程序之類的事情,我們別無選擇,只能使用命令行。 對于其他所有內容,我們將使用GUI。

I also assume you have a Github and Heroku account. They are both free, so no worries about signing up.

我還假設您有一個Github和Heroku帳戶。 它們都是免費的,因此無需擔心注冊。

sample project:https://github.com/iqbal125/react-express-sample

示例項目: https : //github.com/iqbal125/react-express-示例

React和快速設置 (React and Express Setup)

First, let's start by creating two directories named Server and Client.

首先,讓我們開始創建兩個名為ServerClient的目錄

The Client directory will hold the contents of the create-react-app command, and Server will hold the contents of the express command. This library just creates a simple Express app for us automatically, similar to create-react-app. It needs to be installed globally, which you can do so with the command:

Client目錄將保存create-react-app命令的內容,而Server將保存express命令的內容。 這個庫只是為我們自動創建一個簡單的Express應用,類似于create-react-app 。 它需要全局安裝,您可以使用以下命令進行安裝:

npm install -g express-generator

npm install -g express-generator

After this, simply run these commands in each of the respective directories to install the starter projects:

之后,只需在每個相應的目錄中運行以下命令來安裝入門項目:

npx create-react-app app1 in the Client directory

客戶端目錄中的npx create-react-app app1

express in the Server directory

express服務器目錄

Change to the app1 directory generated by create-react-app and run:

轉到由create-react-app生成的app1目錄,然后運行:

npm run build

npm run build

This will generate a production build version of the project that is optimized for a production deployment, with things like the error handling code and white space removed. ?

這將生成該項目的生產構建版本,該版本針對生產部署進行了優化,并刪除了錯誤處理代碼和空白。

Note: In a development build you would use a proxy to http://localhost:5000 to communicate from your React app to your Express server, but here the React app and the Express server are just one project. The Express server serves the React files.

注意:在開發構建中,您將使用http:// localhost:5000的代理從您的React應用程序與Express服務器進行通信,但是在這里,React應用程序和Express服務器只是一個項目。 Express服務器提供React文件。

Next, cut and paste the entire build directory into the Server directory. Your project structure should look like this:

接下來,將整個構建目錄剪切并粘貼到Server目錄中。 您的項目結構應如下所示:

We can now add some code to let our Express server know to serve our React project.:

現在,我們可以添加一些代碼來讓Express服務器知道為我們的React項目提供服務:

....app.use(express.static(path.join(__dirname, 'build')));app.get('/*', (req, res) => {res.sendFile(path.join(__dirname, 'build', 'index.html'));
});....

The first line of code serves all our static files from the build directory.

第一行代碼為構建目錄中的所有靜態文件提供服務。

The second piece of code is to keep our client side routing functional. This code essentially serves the index.html file on any unknown routes. Otherwise we would need to rewrite our entire routing to work with this Express server setup.

第二段代碼是保持我們的客戶端路由功能正常。 此代碼本質上在任何未知路由上提供index.html文件。 否則,我們將需要重寫整個路由以與此Express服務器設置一起使用。

To test your app, just run npm start in the Server directory and go to http://localhost 3000 in the browser. Then you should be see your running React app.

要測試您的應用,只需在Server目錄中運行npm start并在瀏覽器中轉到http:// localhost 3000 。 然后,您應該會看到正在運行的React應用程序。

Now we are ready to upload this project to GitHub.

現在,我們準備將這個項目上傳到GitHub。

的GitHub (GitHub )

Instead of using the command line to upload to GitHub, we will do this with the GUI. First, go to the GitHub homepage and create a new repository. Name it whatever you want, but make sure the Initialize this Repository with a README option checked:

我們將使用GUI來執行此操作,而不是使用命令行將其上傳到GitHub。 首先,轉到GitHub主頁并創建一個新的存儲庫。 將其命名為任意名稱,但請確保選中了使用README初始化此存儲庫選項:

Next upload all the project files without the node_modules directory.

接下來,上載所有沒有node_modules目錄的項目文件。

Click commit and we are done. Your uploaded project files will appear on GitHub like so:

單擊提交,我們就完成了。 您上傳的項目文件將出現在GitHub上,如下所示:

Now we can move on to setting up Heroku.

現在我們可以繼續設置Heroku。

Heroku (Heroku)

Go to the Heroku dashboard, create a new app, and name it whatever you like.

轉到Heroku儀表板,創建一個新應用,然后根據需要命名。

Next, go to the Deploy tab and select GitHub under Deployment method:

接下來,轉到Deploy選項卡,然后在Deployment method下選擇GitHub:

If you haven't connected your GitHub account to your Heroku account yet, you will be prompted through the GitHub Auth flow.

如果尚未將GitHub帳戶連接到Heroku帳戶,則將通過GitHub Auth流程提示您??。

After this, search for your project on GitHub and connect to it:

之后,在GitHub上搜索您的項目并連接到它:

Finally, we can just deploy our app by clicking the Deploy Branch button:

最后,我們可以通過單擊Deploy Branch按鈕來部署我們的應用程序:

Heroku will install all the Node modules for you automatically. You can view your project by clicking on the View button.

Heroku將自動為您安裝所有Node模塊。 您可以通過單擊查看按鈕來查看您的項目。

And that's it, we're done! Thanks for reading.

就是這樣,我們完成了! 謝謝閱讀。

Connect with me on Twitter for more updates on future tutorials: https://twitter.com/iqbal125sf

在Twitter上與我聯系以獲取未來教程的更多更新: https : //twitter.com/iqbal125sf

翻譯自: https://www.freecodecamp.org/news/deploy-a-react-node-app-to/

react部署在node

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391138.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391138.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391138.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

深入理解InnoDB(7)—系統表空間

系統表空間 可以看到,系統表空間和獨立表空間的前三個頁面(頁號分別為0、1、2,類型分別是FSP_HDR、IBUF_BITMAP、INODE)的類型是一致的,只是頁號為3~7的頁面是系統表空間特有的 頁號3 SYS: Insert Buffer …

CodeForces - 869B The Eternal Immortality

題意&#xff1a;已知a,b&#xff0c;求的最后一位。 分析&#xff1a; 1、若b-a>5&#xff0c;則尾數一定為0&#xff0c;因為連續5個數的尾數要么同時包括一個5和一個偶數&#xff0c;要么包括一個0。 2、若b-a<5&#xff0c;直接暴力求即可。 #include<cstdio>…

如何在24行JavaScript中實現Redux

90% convention, 10% library. 90&#xff05;的慣例&#xff0c;10&#xff05;的圖書館。 Redux is among the most important JavaScript libraries ever created. Inspired by prior art like Flux and Elm, Redux put JavaScript functional programming on the map by i…

卡方檢驗 原理_什么是卡方檢驗及其工作原理?

卡方檢驗 原理As a data science engineer, it’s imperative that the sample data set which you pick from the data is reliable, clean, and well tested for its usability in machine learning model building.作為數據科學工程師&#xff0c;當務之急是從數據中挑選出的…

Web UI 設計(網頁設計)命名規范

Web UI 設計命名規范 一.網站設計及基本框架結構: 1. Container“container“ 就是將頁面中的所有元素包在一起的部分&#xff0c;這部分還可以命名為: “wrapper“, “wrap“, “page“.2. Header“header” 是網站頁面的頭部區域&#xff0c;一般來講&#xff0c;它包含…

leetcode 1486. 數組異或操作(位運算)

給你兩個整數&#xff0c;n 和 start 。 數組 nums 定義為&#xff1a;nums[i] start 2*i&#xff08;下標從 0 開始&#xff09;且 n nums.length 。 請返回 nums 中所有元素按位異或&#xff08;XOR&#xff09;后得到的結果。 示例 1&#xff1a; 輸入&#xff1a;n …

27個機器學習圖表翻譯_使用機器學習的信息圖表信息組織

27個機器學習圖表翻譯Infographics are crucial for presenting information in a more digestible fashion to the audience. With their usage being expanding to many (if not all) professions like journalism, science, and research, advertisements, business, the re…

在HTML中使用javascript (js高級程序設計)

在HTML中使用javascript 剛開始入門的時候覺得關于應用以及在html中只用javascript很簡單&#xff0c;不需要進行學習。我又開始重溫了一下紅寶書&#xff0c;覺得還是有必要進行學習的。這是一個筆記&#xff01; script 元素插入有多種方式 屬性使用方式async延遲腳本&#x…

大數據新手之路二:安裝Flume

Ubuntu16.04Flume1.8.0 1.下載apache-flume-1.8.0-bin.tar.gz http://flume.apache.org/download.html 2.解壓到/usr/local/flume中 3.設置配置文件/etc/profile文件&#xff0c;增加flume的路徑 ①vi /etc/profile export FLUME_HOME/usr/local/flume export PATH$PATH:$FLUME…

leetcode 1723. 完成所有工作的最短時間(二分+剪枝+回溯)

給你一個整數數組 jobs &#xff0c;其中 jobs[i] 是完成第 i 項工作要花費的時間。 請你將這些工作分配給 k 位工人。所有工作都應該分配給工人&#xff0c;且每項工作只能分配給一位工人。工人的 工作時間 是完成分配給他們的所有工作花費時間的總和。請你設計一套最佳的工作…

異步解耦_如何使用異步生成器解耦業務邏輯

異步解耦Async generators are new in JavaScript. They are a remarkable extension. They provide a simple but very powerful tool for splitting programs into smaller parts, making sources easier to write, read, maintain and test.異步生成器是JavaScript中的新增功…

函數的定義,語法,二維數組,幾個練習題

1、請將’A’,’B’,’C’存入數組&#xff0c;然后再輸出2、請將”我” “愛” “你”存入數組&#xff0c;然后正著和反著輸出3、輸入10個整數存入數組&#xff0c;然后復制到b數組中輸出4、定義一個長度為10的數組&#xff0c;循環輸入10個整數。 然后將輸入一個整數&#x…

leetcode 1482. 制作 m 束花所需的最少天數(二分查找)

給你一個整數數組 bloomDay&#xff0c;以及兩個整數 m 和 k 。 現需要制作 m 束花。制作花束時&#xff0c;需要使用花園中 相鄰的 k 朵花 。 花園中有 n 朵花&#xff0c;第 i 朵花會在 bloomDay[i] 時盛開&#xff0c;恰好 可以用于 一束 花中。 請你返回從花園中摘 m 束…

算法訓練營 重編碼_編碼訓練營手冊:沉浸式工程程序介紹

算法訓練營 重編碼Before you spend thousands of dollars and several months of your life on a coding bootcamp, spend 30 minutes reading this handbook.在花費數千美元和一生中的幾個月時間參加編碼訓練營之前&#xff0c;請花30分鐘閱讀本手冊。 這本手冊適用于誰&…

面向Tableau開發人員的Python簡要介紹(第4部分)

用PYTHON探索數據 (EXPLORING DATA WITH PYTHON) Between data blends, joins, and wrestling with the resulting levels of detail in Tableau, managing relationships between data can be tricky.在數據混合&#xff0c;聯接以及在Tableau中產生的詳細程度之間進行搏斗之間…

bzoj 4552: [Tjoi2016Heoi2016]排序

Description 在2016年&#xff0c;佳媛姐姐喜歡上了數字序列。因而他經常研究關于序列的一些奇奇怪怪的問題&#xff0c;現在他在研究一個難題&#xff0c;需要你來幫助他。這個難題是這樣子的&#xff1a;給出一個1到n的全排列&#xff0c;現在對這個全排列序列進行m次局部排序…

oracle之 手動創建 emp 表 與 dept 表

說明&#xff1a; 有時候我們需要通用的實驗數據&#xff0c;emp表 與 dept表 但是數據庫中有沒有。 這時&#xff0c;我們可以手動創建。 -- 創建表與數據CREATE TABLE EMP(EMPNO NUMBER(4) NOT NULL, ENAME VARCHAR2(10), JOB VARCHAR2(9), MGR NUMBER(4), HIREDATE DATE, S…

深入理解InnoDB(8)—單表訪問

1. 訪問方法 MySQL把執行查詢語句的方式稱之為訪問方法或者訪問類型。 而訪問方法大致分為兩類 全表掃描索引 而進行細分的話可以分為以下幾類 &#xff08;為了方便說明&#xff0c;先建一個表&#xff09; CREATE TABLE single_table (id INT NOT NULL AUTO_INCREMENT,key…

蝙蝠俠遙控器pcb_通過蝙蝠俠從Circle到ML:第二部分

蝙蝠俠遙控器pcbView Graph查看圖 背景 (Background) Wait! Isn’t the above equation different from what we found last time? Yup, very different but still looks exactly the same or maybe a bit better. Just in case you are wondering what I am talking about, p…

camera驅動框架分析(上)

前言 camera驅動框架涉及到的知識點比較多&#xff0c;特別是camera本身的接口就有很多&#xff0c;有些是直接連接到soc的camif口上的&#xff0c;有些是通過usb接口導出的&#xff0c;如usb camera。我這里主要討論前者&#xff0c;也就是與soc直連的。我認為凡是涉及到usb的…