By sharsh2106
i’ve just build a multivendor ecommerce webapp using mern stack its a giant project
Now i want to deploy this webapp on digital ocean
Now i just want to know how do i deploy like deploy directly on digital ocean using nginx firewall etc Or Should i use docker/kubernetes then after containerization go for digital ocean
Or
If you know a better way to deploy im open to suggestions
-i’ll be using two servers one for mongodb and other for react and node,If you think if im doing it wrong please correct me
-or should i use 3 server for backend,frontend and mongodb respectively
-what’s your opinion how should i do things
This webapp is going to get around 5000-10000 Per day visits
Last question should i use one git repo like combined backend+fronent Or should i use two repo one for frontend and other for backend
Any suggestion on folder structure for this big webapp
Please help im really stuck and confuse
if im doing anything wrong do correct me
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi there,
Deploying a MEAN (MongoDB, Express.js, AngularJS, Node.js) stack application on an Ubuntu Droplet involves several steps.
Firstly, you need to ensure that all necessary software is installed on your Ubuntu server. Then, you’ll need to deploy both the backend (Express.js/Node.js) and the frontend (AngularJS) applications.
Here are some high-level steps on how you can accomplish this:
Step 1: Set up the Ubuntu Server
Update the package list on the server:
sudo apt-get update
Install curl and some other necessary software:
sudo apt-get install curl gnupg build-essential
Step 2: Install Node.js
Install Node.js via the NodeSource repository:
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs
For mode details on how to install Node.js I would suggest this tutorial here.
Check the installed Node.js and npm versions:
node -v
npm -v
Step 3: Install MongoDB
To install MongoDB, follow the steps from this tutorial here
Or alternatively, you can use the managed MongoDB database clusters provided by DigitalOcean:
Step 4: Deploy the Backend (Express.js/Node.js) App
Clone your application from your Git repository (replace <your-git-repo> with your repository URL):
git clone <your-git-repo>
Navigate into your project folder and install dependencies:
cd <your-project-folder>
npm install
Start your Express.js/Node.js app (assuming your main file is server.js):
node server.js
Alternatively, I would recommend using pm2 to run your Node.js service so that you don’t have to worry about the process stopping when you close your terminal:
How To Set Up a Node.js Application for Production on Ubuntu 20.04
Step 5: Install Nginx
Update the package list:
sudo apt-get update
Install Nginx:
sudo apt-get install nginx
Step 6: Deploy the Frontend (AngularJS) App
Build your AngularJS app on your local machine:
ng build --prod
Copy the dist/ folder (which was created by the build command) to your server. You can use a tool like scp for this.
On your server, move the contents of the dist/ folder to Nginx’s html directory (replace <angular-project-name> with the name of your Angular project):
sudo mv dist/<angular-project-name>/* /var/www/html/
Step 7: Configure Nginx
Open the Nginx configuration file:
sudo nano /etc/nginx/sites-available/default
Replace the contents of the file with the following (replace <your-node-app-location> with the path to your Node.js app’s server.js file):
server {
listen 80;
server_name _;
location / {
proxy_pass http://localhost:3000; # assuming your Express app runs on port 3000
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Restart Nginx to apply the changes:
sudo systemctl restart nginx
Your MEAN stack application should now be deployed on your Ubuntu server. Users should be able to access your AngularJS app by navigating to your server’s IP address or domain name in their web browser. The AngularJS app will interact with the Express.js/Node.js app as necessary.
A few remarks to keep in mind:
These instructions assume that your Express.js/Node.js app runs on port 3000. If it runs on a different port, adjust the proxy_pass line in the Nginx configuration file accordingly.
As mentioned above, for a production deployment, it’s recommended to use a process manager like PM2 to keep your Node.js app running even after the server restarts or the app crashes.
You should also secure your application by installing an SSL certificate. Let’s Encrypt provides free SSL certificates and is compatible with Nginx. How To Secure Nginx with Let’s Encrypt on Ubuntu 20.04 will walk you through the process.
Depending on the size and requirements of your application, it might be more appropriate to use a cloud-based database service, such as a Managed MongoDB instance, instead of running MongoDB directly on your server.
Hope that this helps!
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.