<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Muhammad Owais Warsi</title>
    <description>The latest articles on Forem by Muhammad Owais Warsi (@muhammadowaiswarsi).</description>
    <link>https://forem.com/muhammadowaiswarsi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1267590%2F6293a9bb-aa82-4d0c-a735-f2e01481dbd4.jpg</url>
      <title>Forem: Muhammad Owais Warsi</title>
      <link>https://forem.com/muhammadowaiswarsi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/muhammadowaiswarsi"/>
    <language>en</language>
    <item>
      <title>How to deploy React and Node application on render ?</title>
      <dc:creator>Muhammad Owais Warsi</dc:creator>
      <pubDate>Wed, 02 Oct 2024 10:03:24 +0000</pubDate>
      <link>https://forem.com/muhammadowaiswarsi/how-to-deploy-react-and-node-application-on-render--m24</link>
      <guid>https://forem.com/muhammadowaiswarsi/how-to-deploy-react-and-node-application-on-render--m24</guid>
      <description>&lt;p&gt;As a beginner deploying your projects can be confusing and a bit overwhelming. In today's post I'll be talking about how to deploy your React(Vite) and Node application on render.&lt;/p&gt;

&lt;p&gt;If you want to know more about render, here it is &lt;a href="https://render.com/" rel="noopener noreferrer"&gt;https://render.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's Begin 🚀 🚀&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd366m9zdo5btj2sdx1da.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd366m9zdo5btj2sdx1da.gif" alt="Let's Begin" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Render account.&lt;/li&gt;
&lt;li&gt;GitHub/GitLab repository.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I'm assuming that your folder structure somewhat look's like this. &lt;br&gt;
Folder names can be different.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.
├── client
└── server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First of all we have to create a &lt;code&gt;package.json&lt;/code&gt; file in the root directory. The file should contains the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "test",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "install-server": "cd server &amp;amp;&amp;amp; npm install",
    "start-server": "cd server &amp;amp;&amp;amp; node index.js",
    "install-client": "cd client &amp;amp;&amp;amp; npm install",
    "build-client": "cd client &amp;amp;&amp;amp; npm run build",
    "start-client": "cd client &amp;amp;&amp;amp; npm run start"
  },
  "author": "",
  "license": "ISC",
  "description": ""
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The main part lies in the scripts. Now after adding the &lt;code&gt;package.json&lt;/code&gt; into your root directory, push the entire project to GitHub/GitLab.&lt;/p&gt;

&lt;p&gt;Now after after completing all the above procedures, we'll move on &lt;br&gt;
to render. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Remember to make the build of your react project using the command &lt;br&gt;
&lt;code&gt;npm run build&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So the basic logic is that we'll deploy our frontend and backend seperately and will connect them.&lt;/p&gt;
&lt;h2&gt;
  
  
  Deploying on Render
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Deploying the Client&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new project on render and select static site.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl6ha33os5fd2soizfe7b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl6ha33os5fd2soizfe7b.png" alt="static site" width="292" height="479"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2.Connect your repository.&lt;/p&gt;

&lt;p&gt;3.Enter the build command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run install-client &amp;amp;&amp;amp; npm run build-client
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4.Enter yout publish directory. In vite application it's&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./client/dist
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here &lt;code&gt;client&lt;/code&gt; is the folder name and can be changed as per your folder name.&lt;/p&gt;

&lt;p&gt;5.Then add you enviroment variables if any.&lt;/p&gt;

&lt;p&gt;6.Finally click on &lt;strong&gt;Deploy&lt;/strong&gt; and wait for sometime for the completion.&lt;/p&gt;

&lt;p&gt;After it's successfuly deployed you can see tag &lt;code&gt;Live&lt;/code&gt; and get a URL of your site. &lt;/p&gt;

&lt;p&gt;Now copy this URL and place it in your backend application &lt;code&gt;cors&lt;/code&gt; so that it does'nt throw cors error in future.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cors({
   origin : your-static-site-url 
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Deploying the server&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Again create a new project , but this instead of static site create a web service.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Again chose the same repository.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter the build command&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run install-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Enter the start command
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run start-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Then enter your enviroment variables if any.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;code&gt;Deploy&lt;/code&gt; and wait for some time.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When it's finally deployed, take the URL and replace it everyehere in your frontend code wherever you hit request to backend.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For example if your URL was &lt;code&gt;localhost:3000/create-user&lt;/code&gt; change it to &lt;code&gt;your-web-service-url/create-user&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Make all the changes and finally test your application. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this guide we have discussed, how to deplaoy your react and node application on render. &lt;/p&gt;

&lt;p&gt;If you found this guide helpful, let me know in the comments and share it with others who might benifit.&lt;/p&gt;

&lt;p&gt;Hope you liked the guide. Thanks for reading 😊&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>node</category>
      <category>cloud</category>
    </item>
  </channel>
</rss>
