can one of you tell me how can I deploy my mern app? not free render or vercel. to my own site test123.com etc. what is needed? visual machine or cpanel or something?? I’m getting angry about this. there is no proper guide to deploy mern app. Any idea how to deploy without having so many troubles? I’ve already spent almost a full day on it. I’ve tried all the methods. Im using npm. helphelphelphelphelp helphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelphelpv
2
Answers
Deploying a MERN app to your own site requires a few steps. Here are some outline of the process:
Acquire a Domain and Hosting: First, you need to own a domain name like test123.com. You can purchase a domain from a domain registrar like GoDaddy or Namecheap. Additionally, you’ll need a hosting provider where you can deploy your MERN app. A Virtual Private Server (VPS) or a cloud provider like AWS, DigitalOcean, or Linode are popular options. These services provide virtual machines (VMs) to host your application.
Set Up the Server: Once you have a hosting provider, you’ll need to set up your server. This involves provisioning a virtual machine, installing the required software (e.g., Node.js, MongoDB), configuring the server environment, and securing the machine. The process varies depending on the hosting provider, but they typically offer tutorials or documentation on how to set up a server.
Transfer Your MERN App: Once your server is ready, you’ll need to transfer your MERN app’s code to the server. You can do this via SSH (Secure Shell) or FTP (File Transfer Protocol) using tools like FileZilla or SCP (Secure Copy). Copy your app’s files to a directory on the server.
Install Dependencies: SSH into your server and navigate to the directory where your app’s files are located. Use the terminal or command line to install the required dependencies for your MERN app. Run npm install in the server’s terminal to install the app’s dependencies specified in the package.json file.
Build the Frontend: If you’re using a client-side framework like React, you’ll need to build your frontend before deployment. Run npm run build in the terminal to create a production-ready version of your React app. This generates optimized static files that will be served by the server.
Configure Environment Variables: Many MERN apps rely on environment variables for configuration. Ensure that your server is properly configured with the necessary environment variables. This typically involves creating a .env file on the server and setting the appropriate variables.
Set Up Reverse Proxy: To route incoming requests to your app, you’ll need to set up a reverse proxy. Popular choices include Nginx and Apache. Configure the reverse proxy to forward requests from your domain (e.g., test123.com) to the specific port or address where your Node.js app is running.
Start Your Backend Server: Launch your Node.js server application. You can use tools like PM2 or Forever to ensure that your app stays running even if the server restarts.
Test and Debug: At this point, your MERN app should be running on your domain. Visit your website (e.g., test123.com) in a web browser to test if everything is working as expected. Check the server logs for any errors or warnings that might have occurred during deployment.
you can try this steps and Keep in mind that the specific steps and configurations may vary depending on your app’s requirements and the hosting provider you choose.
Deploying a MERN application can be frustrating if you don’t have proper guidance. I’ll walk you through a simple way to deploy your MERN app on a server that you can manage. This example will use a virtual private server (VPS) as it gives you more control compared to shared hosting with cPanel.
Get a Domain Name
Since you mentioned you want to deploy it on your own site like test123.com, make sure you own a domain name. You can buy one from domain registrars like GoDaddy, Namecheap, or Google Domains.
Get a Virtual Private Server (VPS)
You need a server to host your MERN application. You can get a VPS from providers like DigitalOcean, AWS, Linode, or Vultr, If you are a new user with VPS providers, you can often receive free credits to test your applications. I have written an article that offers a comparison of VPS prices, which you might find helpful. Check out my VPS price comparison article here.
Point Domain to VPS
Change the DNS settings of your domain to point to the IP address of your VPS. This might take a few hours to propagate.
SSH into your VPS: Use SSH to connect to your VPS. For example:
Setup your Environment
Update your package lists
Install Node.js:
Install MongoDB:
Install Nginx (For reverse proxy):
Upload your Code: Use scp or rsync to upload your MERN app code to your VPS. Example:
Install Dependencies and Start Your App: Navigate to your app’s directory on the server and install the dependencies:
Setup Nginx as a Reverse Proxy: Edit the Nginx configuration file:
And add a configuration like:
Save and exit, then restart Nginx:
Configure Firewall: Allow HTTP and SSH through the firewall:
Access Your Site
You should now be able to access your MERN app at your domain name, test123.com.
You might also want to consider securing your server with SSL using Let’s Encrypt, securing your MongoDB database, and setting up a process manager like PM2 for your Node.js application. Hope this helps.