How to deploy Mean.js application to Linux VPS? Print

  • 0

Upload Mean.js Files via SFTP In FileZilla

Once your mean.js webcontent is ready, you need to perform following steps to upload it to your Linux VPS via SFTP.We have used FileZilla FTP client in this article.

  1. Open FileZilla.
  2. Click on “New Site” button.

    Create new sftp connection

  3. Enter following details and click on Connect.

    Host: Your server/VPS IP addressPort: 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 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 webcontent here.

    Mean js app web space

Auto-start Mean.js Application On Boot

Once, you upload your application, It is crucial to keep get your application auto-started after a reboot, shutdown or system crash event.You just need to add a cronjob with following steps.

  1. Login into your Linux VPS via ssh.
  2. Create a new file in your application's home folder with name can choose any name ending with .sh extension).
    cd /home/folder/path/of/your/application
    Add below script to the file.
    if [ $(ps -e -o uid,cmd | grep $UID | grep node | grep -v grep | wc -l | tr -s "\n") -eq 0 ]
            export PATH=/usr/local/bin:$PATH
            forever start --sourceDir /home/folder/path/of/your/application main.js >> /path/to/log.txt 2>&1
    Replace the main.js with your application’s main script file and -sourceDir path should be the path where your upload your mean.js webcontent.

  3. Create a cronjobto autorun this script on each reboot.
    crontab -e
    And add following code:
    @reboot /path/to/this/script/

Please note that you will need to create this for each of your website.

Point Domain To Your Mean.js Application

You need to point your domain to created application so you can access it with

To accomplish this, you need to install a Nginx Web Server with following steps.

  1. Login as Root user to the your server/VPS via SSH.
  2. Run the installation command
    sudo apt-get install Nginx -y
  3. In order to specify your domain linking to your server’s IP address, create new .conf file with yourdomainname.conf
    nano /etc/nginx/conf.d/
    Add following code:
    server {
        listen 80;
        server_name; # 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 with your and http://localhost:{YOUR_PORT} with http://VPS-IP-address:3000;

  4. Start the Nginx webserver service.
    sudo /etc/init.d/nginx start
  5. Now at the DNS management console of your domainname, create A record to point to IP address of the server on which your application is running.

DNS propagation generally takes few hours to get propagated over the globe.After that, you will be able to access your application on the webbrowser.

Please note that you will need to create a separate .conf file at for all websites you add to your VPS.

Was this answer helpful?

« Back
Sign up for a newsletter