How to Deploy a Node Express app Backend on Render step by step?

How to Deploy a Node Express app Backend on Render step by step?

Step by step seamless Deployment Guide/Tutorial: Deploying your Node Express app Backend on Render

1. Name

Put whatever name you want, it doesn't matter.

2. Region

Put the nearest region by yourself.

3. Branch

In the context of Render, the "branch" field refers to the branch of your Git repository that you want to deploy. By default, it's set to "main," but you should go to your GitHub repository and check which branch you want to deploy, especially if you have multiple branches.

4. Root Directory

In Render, the "Root Directory" refers to the main directory within your project's codebase from which the deployment process should start. It serves as the starting point for Render to build and deploy your application. I faced an issue once when I had both frontend and backend within the same repository. It is generally recommended to keep them separate, but if you choose to have them in the same repository, it's essential to specify only the backend directory (folder) in the Root Directory field. In most projects, the Root Directory field in Render can be left empty.

5. Runtime

We are discussing MERN apps, so in this case, the Root Directory field in Render should be set to "Node".

6. Build Command

In most cases, you should enter "npm install" in this field. Here, it is typically a script that installs libraries.

7. Start Command

In most MERN projects, you should enter "npm run server" in this field, it is most used command for starting the server. To identify the exact run script name, you can refer to your project's package.json file. Within this file, there is typically a "scripts" section where you can find the available run scripts. Look for the script that corresponds to starting the server, which is usually defined by the "server" or a similar descriptive name.

8. Advanced, Environment Variables

Make sure to include your environment variables by copying and pasting them from your .env file. Remember to add the .env file to your .gitignore to keep it secure. Additionally, if you have deployed your frontend and your .env file contains the frontend URL, make sure to update it to the production URL.

More about the topic

The best video on YouTube about the topic

Render documentation