Sunday, 10 December 2017

How to install mongodb on an ubuntu EC2 instance

Follow these simple steps to set up mongodb into an ec2 ubuntu instance


  • Import public key
    • sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
  • Create a list file
    • echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
  • sudo apt-get update
  • sudo apt-get install -y mongodb-org
  • Start a service 
    • sudo service mongod star    
      • **In my case: Job was already running
  • Connect the mongo... :)
    • mongo
  •  Stop the service ..If you want.
    • sudo service mongod stop

Deploy Angular4 application on an ec2 instance


Here are the some easy steps to deploy an angular4 application into an ec2 instance


  • install angular-cli
    •  sudo npm install -g @angular/cli

  • node with version greater than 6 must be installed 
    • see my last post describes to setup an node application
  • Port should be open from security group inbound rules.
  • Clone the repo:-
  • Run: 
    • npm install
  • serve to required port and public ip
    •   ng serve --disable-host-check --host 0.0.0.0 --port 3100  --public  xx.xx.xx.xxx
  • Run in background 
    • Start a client
      • nohup ng serve --disable-host-check --host 0.0.0.0 --port 3100  --public  xx.xx.xx.xxx  1>./log.txt 2>./err.txt &
    • Stop a client 
      • kill $( lsof -t -i:3100)
    • Or by using screen

How to publish an Node application on Ubuntu.

Do you have a dream of seeing your nodeJS application running on a live server?  

But all such dreams ended up in a nightmare because you don't know anything about how to use a remote machine? And the dream remains a dream throughout your lifetime.

If so then I have my empathy for you because I had been sharing the same nightmare a few days ago ever since when a friend of mine made this simple and made me took a step ahead. 

Let me make it 

Prerequisites:

  1. Make sure you have a running remote machine in Ubuntu14.04, say EC2 instance. If you don't know how to set up a remote machine I promise I will help you up in my upcoming posts.
  2. You have an established connection to the remote machine. So that you can access your remote machine. You can use any client say Putty or directly the ssh command. Will surely post about this well.

Here are some very simple bullets points to set up a node application:

After you successfully connected to the remote server, you must be seeing something like this on your terminal. 

Now start following these points


1) Update Advance packaging tool  

  • sudo apt-get update

2) Install npm
  • sudo apt-get install npm
3) Install nvm :
  • sudo wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh | sudo bash
  •  Re-start the terminal
  • nvm install v9.2.0
  • more details   
4) Install git
  • sudo apt-get install git
5) Install babel-cli
sudo npm install -g babel-cli
6) Install MongoDB: details in my next post Also to run an application in port 80, you need to run the application with sudo, since only a super user can access ports below 1024.
7) git clone the repo and start with babel-node server.js
























8) Run the application in background (In case of remote server like an ec2 instance)

  • Start a server :sudo nohup babel-node server.js  1>./log.txt 2>./err.txt &
  • Stop a server : sudo kill $(sudo lsof -t -i:5000)
  • Or by using screen: