Question

How to deploy MERN Stack

Posted January 11, 2021 4.7k views
Node.jsReact

hi

I have a MERN app with MongoDB Atlas as my database. Both backend and the frontend is in a folder call MyApp. In my My App folder, I have a server.js with express and cors and API routes and other stuffs. Also in the MyApp folder, I have a folder called frontend which is a React App. I have test locally and works well. HTTP://localhost:5000 is my backend API and http://localhost:3000, is the frontend React App. I have already setup Nginx and PM2.

Next, how do I deploy this MERN stack to a droplets. Many thanks in advance.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi, Shourov here.
You can deploy your mern stack as a simple nodejs application. What you need to do is, just make a build of reactjs project and include it inside your server dir, then use express static and locate your build reactjs project. use a production route (*) and this will be resolve by the building one. that’s it. your mern is up and running.

or 2nd way you can deploy your backend or server at digital ocean and then you can deploy your frontend at netlify or firebase hosting, but before deploy make sure to use a proxy to fool react app.

  • Thank you, Shourov.

    Is it not possible to deploy both backend and frontend as separate apps but both to Digital Ocean? Why use Netlify if you already have a DO account?