Build a to-do app with MEAN
15 minutes
This tutorial will walk you through:
- Creating and configuring two VMs
- Setting up firewall rules
- Using SSH to install packages on your VMs
Create a back-end VM
First, create the back-end VM that runs MongoDB. This server stores the to-do items.- Click the Create instance buttonClick the Create instance button.
- Name the instanceEnter a name (for example, "back-end") for this instance and press the Tab key to move to the next step
- Select the machine typeSelect f1-micro . This will incur fewer charges. Learn more about pricing
- Select the boot disk imageSelect Ubuntu 14.04 LTS as your boot disk image for this tutorial.
- Open HTTP firewall portOpen HTTP firewall port
Check Allow HTTP traffic. This is an easy way to open firewall 80 (HTTP) so the front-end and back-end VMs can communicate - Create the VMCreate the VM
Click Create to finish creating this instance
Create a front-end VM
While the back-end VM is spinning up, create the front-end VM that runs the Node.js todo application- Create the front-end VMClick Create Instance to create the front-end VM
- Name the instanceEnter a name (for example, "front-end") for this instance and press the Tab key to move to the next step
- Select the machine typeSelect f1-micro . This will incur fewer charges. Learn more about pricing
- Select the boot disk imageSelect Ubuntu 14.04 LTS as your boot disk image for this tutorial.
- Open HTTP firewall portOpen HTTP firewall port
Check Allow HTTP traffic. This is an easy way to open firewall 80 (HTTP) so the front-end and back-end VMs can communicate - Create the VMCreate the VM
Click Create to finish creating this instance
Install and run the back-end database (1)
- SSH into the VMSSH into the VM
Next to your back-end VM, click SSH to open a terminal window in your browser - Install and run the databaseInstall and run the database
Go to the terminal window and enter the commands to install and run MongoDB
Install and run the back-end database (terminal window)
Enter these commands to install and run MongoDB. You can use the keyboard to copy and paste each command line. Click Done when you finish entering all the commands to close the SSH window.
Update packages and install MongoDB. When asked if you want to continue, type 'Y'.
$ sudo apt-get update
$ sudo apt-get install mongodb
The MongoDB service started when you installed it. You must stop it so you can change how it runs.
$ sudo service mongodb stop
Create a directory for MongoDB and then run the MongoDB service in the background on port 80.
$ sudo mkdir $HOME/db ; sudo mongod --dbpath $HOME/db --port 80 --fork --logpath /var/tmp/mongodb
After you enter the final command, click Done and then confirm that you want to leave the page to close the SSH browser window.
Install and run the web app on your front-end VM
The MongoDB back-end server is running, so it is time to install the front-end web application- SSH into the VMSSH into the VM
Next to your front-end VM, click SSH to open a terminal window in your browser - Install and run the web app on your front-end VMInstall and run the web app on your front-end VM
Go to the terminal window and enter the commands to install and run the sample todo app
Install and run the web app on your front-end VM (terminal window)
Enter these commands to install the todo web application. You can use the keyboard to copy and paste each command line. Click Done when you finished entering all the commands to close the SSH window.
Update packages and install git, Node.js and npm. When asked if you want to continue, type 'Y'.
$ sudo apt-get update
$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
$ sudo apt-get install git nodejs
Clone the sample application and install application dependencies.
$ git clone https://github.com/GoogleCloudPlatform/todomvc-mongodb.git
$ cd todomvc-mongodb; npm install
Start the todo web application. Note: The IP addresses below are internal IPs for communication between servers. You can find these IP addresses on each server’s details page.
$ nohup nodejs server.js --be_ip 10.142.0.2 --fe_ip 10.142.0.3 &
After you enter the final command, click Done and then confirm that you want to leave the page to close the SSH browser window.
The quickstart servers continue running until you remove them. This can reduce your available quotas.
You're done
Your app is running at http://35.185.117.209:8080The quickstart servers continue running until you remove them. This can reduce your available quotas.
Where the data is stored?
ReplyDeletehow to view the data entered in todos application?
ReplyDelete