Meteor App Deployment

Ashish
Excited Developers
Published in
3 min readJun 18, 2018

Written By Ashish Pandey and Arshpreet Wadehra

Image Source Hackernoon

Most of the web developers have uploaded static websites before. The process isn’t too tedious, just get a domain and move the files from your computer to the server machine or use Github and WooF! Website.
But Meteor is a different beast and most of the online tutorial wont tell how to host it. Although it isn’t a big deal as you have the option of using MUP, but what will you do if your machine doesn’t supports Docker installation or maybe due to some other issues you can’t use MUP. This article will talk about meteor app deployment manually (i.e without using any third party library).

(P.S This deployment process is for Ubuntu)

  • Login to your server using ssh
  • Install node
sudo apt-get install nodejs 
node -v
npm -v
  • Install pm2 or forever npm package type
sudo npm install pm2 -g
sudo npm install forever -g
  • Setup MongoDB(>v3.0) if not installed (type mongo)

Install MongoDB on Ubuntu

mongod --version (P.S. make sure the version is > 3.0)
sudo systemctl start mongod
mongo
Create db using "use <db_name>" like use myMeteorApp
Now create user for db access using
db.createUser({user:"test",pwd:"test",roles:["readWrite"]})
  • Press Enter to create user user and pwd is in plain text
  • After that you need to enable authentication in MongoDB for that exit mongo shell by ctrl+c
  • Go to /etc/mongod.conf

Find #security:
change to security:
authorization: enabled
systemctl restart mongod
  • After successfully setup Mongo. Our Server is almost setup.
  • Now go to your meteor app project. Open project in command prompt or terminal.
  • If you are pulling it from version control make sure you do npm install in this process. I mean all your npm dependencies must be present in node modules folder.
  • Type meteor build — sever-only ./
  • It will build your project for production use and compress your build in same directory <project_name>.tar.gz
  • Extract your compresses build using tar xzf <project_name>.tar.gz
  • It will give you bundle folder in same directory
  • Now cd bundle/programs/server
  • run npm install — production
  • Now go back to bundle cd ../../
  • Then we need to export or set Environment variables
sudo systemctl start mongod
export MONGO_URL='mongodb://localhost/<dbname>' (i.e myMeteorApp)
export ROOT_URL='http(s)://something' (give your IP if you don't have a domain)
export PORT= 3000 (as per your convenience)
  • After setup Environment variable. Go to bundle directory and run
    pm2 start — name “UID” main.js
  • It will start your server at background you can browse your app <your_ip>:3000 or test via curl localhost:3000
  • Nginx setup
sudo systemctl start mongod
sudo apt-get install nginx
vim /etc/nginx/nginx.conf
Go down you will find http block & inside that block paste belowserver {
listen 80;
server_name domainName.com www.domainName.com; location / { proxy_pass http://127.0.0.1:3000; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header X-Real-IP $remote_addr; proxy_http_version 1.1; proxy_set_header Host $host; proxy_connect_timeout 300; proxy_send_timeout 300; proxy_read_timeout 300; }
}
(Change domainName to your domain and port number according to your settings. Save the file. Restart nginx (systemctl restart nginx))

This is my first medium post so please give your suggestions on how to improve it and correct me if I am wrong anywhere.

Cheers!

--

--