🔥 Checkout our new Azure Developer page at azure.com/developer.
📺 Watch the video : How to build and run a MEAN-based application in Azure.
💡 Learn more : Sample MEAN application GitHub repository
A MEAN application stack is one that is based on MongoDB, Express, AngularJS and Node.js. This is an attractive technology stack, because it is very performant, cost-effective and can run almost anywhere. The technologies in a MEAN-based application can all be free of cost as they are open source. However, you can also choose to pay to get support contracts for these technologies.
Creating a MEAN-based application and running it in Azure is surprisingly simple. Let's take a look at how to do it:
We're going to run the MEAN-based application on a VM in Azure that runs Ubuntu. This will show that this type of application can run on many types of Operating Systems, including Ubuntu.
az vm create \ --resource-group AzureTipsAndTricks \ --name tipsandtrickVM \ --image UbuntuLTS \ --admin-username azuremichael \ --admin-password 'my1stFakePassword!' \ --generate-ssh-keys az vm open-port --port 3300 --resource-group AzureTipsAndTricks --name tipsandtrickVM az vm open-port --port 80 --resource-group AzureTipsAndTricks --name tipsandtrickVM
When the VM is created, you'll see something like the image below. Copy the publicIpAddress value. We'll need that to connect to the VM.
(Results of VM creation in the Azure Cloud Shell)
(SSH into the VM in the Azure Cloud Shell)
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E52529D4
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
sudo apt-get update
sudo apt install mongodb-org
sudo service mongod start
That's it! We have a MongoDB database sever running on the VM. Let's continue with Node.js.
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install nodejs
Now for the easy part: creating the application. We'll use a simple Node.js application that manages books that we store in MongoDB. We'll get the application files from a public GitHub repository.
git clone https://github.com/MicrosoftDocs/mslearn-build-a-web-app-with-mean-on-a-linux-vm
We now have a complete application that we can run. Let's copy it to the VM and run it.
scp -r mslearn-build-a-web-app-with-mean-on-a-linux-vm email@example.com:./
sudo node server.js
The application is now running and listening for requests on the public IP address of the VM. Navigate to this address in a browser to open the application. Try it out by adding and deleting a couple of books.
(Run the application in a browser)