How to Deploy MERN Projects on Heroku

 How to Deploy MERN Projects on Heroku

Before Starting with the deployment of MERN project on Heroku, I will highly recommend you to watch this video first on SSH

Also, I want you to watch the video too. Here I already show about how to do registration and login in Heroku app.

I will tell you the steps to follow, And there are many different ways to do it, So what we are looking is one of the best way to do it ok.

1: Copy and Paste the Client folder inside the Server folder and then delete the client folder outside the server folder.

2: We need to change the PORT number from Static to Dynamic for Heroku

Now, first delete the PORT from the .env file and simply write

const PORT = process.env.PORT || 5000;

on the server app.js file.

3: We need to tell the Heroku to serve the statics files of the client.

ð  We need to go to client folder and then run npm build. It will create a build folder and that is the folder which we want to serve on Heroku as a frontend.

C:\xampp\htdocs\SourceCode\MERNThapaYoutube\server\client>npm run build

// step 3: Heroku 


if ( process.env.NODE_ENV == "production"){


    const path = require("path");

    app.get("*", (reqres=> {




4: Remove the proxy from the package.json file, if you have any


5: We need to add few scripts on the Server package.json files in order to tell Heroku, what to do and what not to.


 "scripts": {

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

    "start""node app.js",

    "heroku-postbuild""NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"


6: Remove the git file from the Client side, if there is any

Code = rm -rf .git

7: Once all above steps completed, then we will create an application on Heroku

So we need to write

Heroku login

Then simply login on it.

This is how we do..

C:\xampp\htdocs\SourceCode\MERNThapaYoutube\server>heroku login

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

Opening browser to

Logging in... done

Logged in as *************

8: Once login then go to Heroku website to create an Heroku app to host our project

Click on New button on the top right corner. Then give the name of the project, make sure the name of the project must be unique. Then click on create app button to complete the process. 

9: Once you create simply open the Heroku app and that’s it everything was already written there just follow the steps.

=> We need to initialize git to the main MERN folder not individually on each client or server. Before initialize git make sure if there are any git repo already present delete it.


10: At last make sure the add the Config Vars for these we need to go to settings of our app and then fill the database and secret key value that’s it. 

11: At bottom we have our Website APP link and it’s done. 


  1. Bhai website ki theme change karo yaar
    Bahut odd lagti hai
    New style try karo

  2. Bhai website ki theme change karo yaar
    Bahut odd lagti hai
    New style try karo

  3. git : The term 'git' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
    that the path is correct and try again.
    At line:1 char:1
    + git status
    + ~~~

    1. Bro just enter the path name in environment variables...I think you have not installed git bash

    2. open cmd as an administrator and run the command

  4. remote: npm ERR! code ENOENT
    remote: npm ERR! syscall open
    remote: npm ERR! path /tmp/build_7a94f6e5/client/package.json
    remote: npm ERR! errno -2
    remote: npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_7a94f6e5/client/package.json'
    remote: npm ERR! enoent This is related to npm not being able to find a file.
    remote: npm ERR! enoent
    remote: npm ERR! A complete log of this run can be found in:
    remote: npm ERR! /tmp/npmcache.BpuoX/_logs/2021-06-20T06_09_48_057Z-debug.log
    remote: npm ERR! code ELIFECYCLE
    remote: npm ERR! errno 254
    remote: npm ERR! MERN_PROJECT@1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client`
    remote: npm ERR! Exit status 254
    remote: npm ERR!
    remote: npm ERR! Failed at the MERN_PROJECT@1.0.0 heroku-postbuild script.
    remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    remote: npm ERR! A complete log of this run can be found in:
    remote: npm ERR! /tmp/npmcache.BpuoX/_logs/2021-06-20T06_09_48_081Z-debug.log
    remote: -----> Build failed
    remote: We're sorry this build is failing! You can troubleshoot common issues here:
    remote: If you're stuck, please submit a ticket so we can help:
    remote: Love,
    remote: Heroku

    Facing this error please solve

    1. Delete the .GIT file from your server folder also watch the ssh key video if you get any more error contact me

    2. My mail id is

    3. Guys I getting error.... failed to compile node.js app.......not able to resolve since a week... help me out 🙂

  5. Enumerating objects: 207, done.
    Counting objects: 100% (207/207), done.
    Delta compression using up to 8 threads
    Compressing objects: 100% (178/178), done.
    Writing objects: 100% (207/207), 166.70 KiB | 3.47 MiB/s, done.
    Total 207 (delta 36), reused 0 (delta 0), pack-reused 0
    remote: Compressing source files... done.
    remote: Building source:
    remote: -----> Building on the Heroku-20 stack
    remote: -----> Determining which buildpack to use for this app
    remote: ! No default language could be detected for this app.
    remote: HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.
    remote: See
    remote: ! Push failed
    remote: !
    remote: ! ## Warning - The same version of this code has already been built: d70d82ff21c866aac46ca6b166bfb84ba9d660ab
    remote: ! We have detected that you have triggered a build from source code with version d70d82ff21c866aac46ca6b166bfb84ba9d660ab
    remote: ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
    remote: !
    remote: ! If you are developing on a branch and deploying via git you must run:
    remote: !
    remote: ! git push heroku :main
    remote: !
    remote: ! This article goes into details on the behavior:
    remote: !
    remote: Verifying deploy...
    remote: ! Push rejected to ai-utube-tool.
    ! [remote rejected] master -> master (pre-receive hook declined)

  6. I'm facing the above error. Could anyone please help me ? Thank you!

    1. client or server dono foalder se .git file delete karke fir se try karo
      Ho jayega

  7. I have facing build failed and heroku postbuiled failed problem. Please Help me out :)

  8. App works completly fine until i deploy..then this happens
    please help

  9. Removing proxy
    How will we be able to run the application on Development Environment.

    Even without removing proxy it works fine on Both Prod and Dev Environment.

  10. hint: You've added another git repository inside your current repository.
    hint: Clones of the outer repository will not contain the contents of
    hint: the embedded repository and will not know how to obtain it.
    hint: If you meant to add a submodule, use:
    hint: git submodule add server
    hint: If you added this path by mistake, you can remove it from the
    hint: index with:
    hint: git rm --cached server
    hint: See "git help submodule" for more information.

    sir g i face this problem