Express is a powerful, yet lightweight and flexible web application framework for Node.js. In this post we will explore how you can create and deploy an express application in Microsoft Azure.
Prerequisites
First and foremost you need Node.js. Once you have installed Node.js, use the command prompt to install Express.
npm install express
You can also use the ?g switch to install express globally rather than to a specific directory.
In addition, you will need to create a web site in Microsoft Azure that will host the application. If you have the Azure SDK for Node.js then you would already have the command line tools, but if not, use the following command to install the Azure command line tool:
npm install azure-cli
Create an Express App
Once you have installed Node.js, use the command prompt to create the Express scaffolding using the express command. This will install the scaffolding templates for views, controllers and other relevant resources with Jade and Stylus support:
express --css stylus [Your App Name]
Next, run the install command to install the dependencies
npm install
This command will install the additional dependencies that are required by Express. The express command creates a package.json file that will be used by the Azure command tool to deploy the application and the dependencies in Azure.
The express command creates a folder structure for views, controllers and models to which you can add your own. To modify the default view, you can edit the index.jade file under the views folder and add your own mark-up code. The app.js file under the application folder will contain an instance of express:
var express = require('express');var app = express();
You can now use VERBs to start defining routes.
Deploy an Express App
In order to deploy the Express app in Azure, first, install the Azure command tools for Node.js if you don?t have the SDK installed. The next thing you need to do is to get the publish settings from Azure and import it into your Node.js application using the following commands
azure account downloadazure account import
Next, you need to create a web site in Azure, and also create a local git repository inside your application folder.
azure site create [your site name] --git
You can now commit your files to your local git repository and then use it to push for deployment to Azure using the following command:
git push azure master
You are now all set. The express Node.js application is deployed in Azure.