Microsoft Azure

Microsoft's Azure service is very similar to Amazon's AWS. Both can be considered enterprise-level services, and both offer a tremendous level of flexibility and power, with a really slick UI. Surprisingly, even though it's a Microsoft product, you can spin up instances of Linux environments using Azure, as well as host your Node.js and MongoDB apps.

The first thing you will need, like with any other service, is a registered account at http://azure.microsoft.com. You can use an existing Microsoft Live login if you have one; otherwise, you can register for a new account fairly easily. Once you're logged in to the Azure service, the first thing you'll be presented with is your primary dashboard. The icons to the left are all the various services and options available with Azure.

Clicking on the +NEW icon at the bottom-left corner will present you with the
main dialog that you can use to add any new service. For our purposes, we want to
add a website:

  1. Select Compute, Web Site, and From Gallery.
  2. Select Node JS Empty Site from the long list of gallery options. This will create the necessary environment so that you have somewhere you can put your application.
  3. On the screen that follows, provide the URL for your app.
  4. Leave the remaining fields as their default values.
  5. Click on the checkmark icon to complete the setup process, and your website will be created.
  6. The next step is to set up the database server. Again, similar to AWS or Nodejitsu, we will once again select MongoLab as our database service provider.
  7. Click on the +NEW icon again, select Store, and browse the list until you find and select MongoLab.
  8. Click on the next arrow and browse through the various plans. For our needs, we will leave Sandbox selected (since it's free).
  9. Provide a name for your database; in my case, I entered imgploadrdb.
  10. Click on Next again to review and confirm the plan and monthly price (which should be $ 0.00 per month).
  11. Finally, click on the checkmark icon to Purchase this new subscription plan.

After a few seconds, you should be taken back to your dashboard, where you will see entries for both the website and database app service listed:

Now that the database has been created and is ready, we need to include its connection string in our application before we can upload our code:

  1. Click on the database row to select it and go to its overview.
  2. The bottom of this screen will contain a few icons, one of which is labeled as Connection Info (and has an icon that looks like >i). Click on that icon for a modal window, which contains the connection string URI for your new MongoLab database server, to pop up.
  3. Copy that URI to your clipboard.
  4. Edit server.js in your local app and replace the mongoose.connect connection string with the new string you just copied. There is no need to update the username, and password as Azure has already taken care of this for you using the following code:
mongoose.connect('mongodb://your_specific_azure_
mongolab_uri'); mongoose.connection.on('open', ()=>{ console.log('Mongoose connected.'); });

Once that change has been made, save the file, and don't forget to update your local Git repository with the change, as we'll be using Git in the next section to push your code to Azure (just like we did earlier with Heroku):

    $ git commit -am "Azure connection string"

Back at the Azure dashboard, click on Web Site in the All Items list (or filter by websites using the icons on the left toolbar). From this overview screen, locate the Integrate source control section toward the bottom and click on the Set up deployment from source control link. The following screenshot shows what you should see at this point:

Select Local Git repository and then continue by clicking on the next arrow icon.

The screen that follows will present instructions on how to push your local code to the remote Git repository that has just been created for your Azure website. The gist is to add a new Git remote (much like we did earlier with Heroku) that points to your Azure repository, and then push your code:

    $ git remote add azure SPECIFIC_URL_FOR_YOUR_SERVER
    $ git push azure master  

You should notice the Git information screen in your Azure dashboard update in real time as your code starts to push up after the git push command. From the command line, you will see a lot of remote npm install output as well. Once completed, the deployment history in your Azure dashboard will update, showing the information for the last active deployment.

Now that your code has been deployed to your Azure website and your website connection string is pointing to your MongoLab Azure app service, you're ready to give the website a test run. Launch it by pointing your browser to http://yourappname.azurewebsites.net. Azure does a lot of things right, (UI/UX) and has some really powerful options and scaling features available! Taking a quick glance at the dashboard for a website (the preceding screenshot), you can see that there is a lot going on.

There are many different configuration options, as well as health monitoring and general information (FTP settings, website URLs, usage metrics, and so on), so feel free to poke around and explore.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.35.122