Celebrate Our 22nd Anniversary with Huge Savings! Up to 70% Off

How to Deploy the Mean.js Application to Linux VPS?

Upload Mean.js Files via SFTP in FileZilla

Once your mean.js web content is ready, you need to perform the following steps to upload it to your Linux VPS via SFTP. 

We have used the FileZilla FTP client as an example in this article.

1. Open FileZilla.

2. Click on the New Site button.

Create new sftp connection

3. Enter the following details and click on Connect.

Host: Your server/ VPS IP address port: The standard ssh port number is 22. Specify if you are using any non-standard ssh port number.
Protocol: select SFTP- SSH File Transfer Protocol from the drop-down.
Username: SFTP username
Password: SFTP user password

enter sftp details

4. It will connect you to your SFTP user home directory.
Upload your mean.js web content here.

Mean js app web space


Auto-Start Mean.js Application on Boot

Once you upload your application, getting it auto-started after a reboot, shutdown, or system crash event is crucial. You need to add a cronjob with the following steps – 

  1. Log in to your Linux VPS via SSH.
  2. Create a new file in your application's home folder with the name app-autostart.sh (you can choose any name ending with a .sh extension). 
  3. cd /home/folder/path/of/your/application

Nano app-autostart.sh
Add the script mentioned below to the file -

#!/bin/sh

if [ $(ps -e -o uid,cmd | grep $UID | grep node | grep -v grep | wc -l | tr -s "\n") -eq 0 ]

then

        export PATH=/usr/local/bin:$PATH

        forever start --sourceDir /home/folder/path/of/your/application main.js >> /path/to/log.txt 2>&1

fi

Replace the main.js with your application's main script file, and -sourceDir path should be where you upload your mean.js web content.

4. Create a cron job to autorun this script on each reboot. 

crontab -e

And add the following code: -

@reboot /path/to/this/script/app-autostart.sh

Note
You will need to create this for each of your websites.

Point Domain To Your Mean.js Application

You need to point your domain to the created application so you can access it with http://yourwebsitename.com.

To accomplish this, you need to install an Nginx Web Server using the following steps - 

  1. Log in as a Root user to your server/VPS via SSH.
  2. Run the installation command 

sudo apt-get install Nginx -y

3. To specify your domain linking to your server's IP address, create a new .conf file with yourdomainname.conf 

nano /etc/nginx/conf.d/accuweb.com.conf

Add the following code -

server {

    listen 80;

    server_name your-domain.com; # Change the domain name

    location / {

        proxy_pass http://localhost:{YOUR_PORT};  #Change the IP and port on which your application is running

        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;

    }

}

Replace your-domain.com with your websitename.com and http://localhost:{YOUR_PORT} with http://VPS-IP-address:3000;

4. Start the Nginx web server service. 

sudo /etc/init.d/nginx start

5. Create A record to point to the IP address of the server on which your application is running at the DNS management console of your domain name.

DNS propagation generally takes a few hours to get propagated over the globe. After that, you can access your application on the web browser.

Note
You must create a separate .conf file for all websites you add to your VPS.

 



Was this answer helpful?

« Back

chat