Beginner’s Guide to Node.js on Windows Azure
In this post, I will provide an introduction to Node.js and Windows Azure tools for Node.js and will also provide few resources to start and develop Node.js apps on Windows Azure.
Introduction to Node.js
The Node.js website is given the following introduction on Node.js
“Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.”
Node.js is created by Ryan Dahl in 2009 and supported by his employer Joyent. Node.js is an open-source server-side JavaScript platform for building high performance scalable network programs. Node.js is built on the top of Google's V8 JavaScript engine and the framework is also using other two open source projects libev and libeio. Node.js uses a non blocking and event-driven I/O model which provides the ability to handle thousands of parallel operations with greater performance. Node.js is popular for its performance and the Node.js apps are executed on the V8 runtime engine. Node.js lets the developers to write JavaScript programs on the server-side and its provides a JavaScript API to access the network and file systems. Node.js is providing the highly efficient TCP/IP networking features with the support of powerful asynchronous programming model which lets the developers to build highly scalable real-time apps. Ryan Dahl is mainly created the Node.js framework for building highly scalable real-time apps that communicating with larger audience in the web.
Node is not a solution for every problems, but it is a great platform for some specific problems. Since Node is capable for handling thousands concurrent requests, it is a great platform for building highly scalable systems. Node is good platform form building JSON based HTTP APIs, next generation real-time and collaborative web apps, Single page apps, Streaming data and many type of network programs. Today many organizations are adopting Node.js for their server-side stack for the Mobile apps. Big companies such as Linkedin, Walmart, Yahoo, Google and Mozilla are using Node.js for their apps.
Installing Node.Js on Windows
You can download the Node.js installer for Windows from here. After installing the Node.js, you can run Node programs from the Windows command-line. The iisnode project which allows to hosting node.js apps on IIS web server. The documentation of iisnode page is available from here.
NPM
npm is a package manager for node.js programs.You can use npm to install node modules created by community. npm manages dependencies of node modules. npm is very similar to NuGet in the .Net. To install a Node module, run the npm command as shown in the below
npm install <module name>
The following command will install a node module express
npm install express
Creating a HTTP Server using Node.js
Let’s create a simple HTTP server using Node.js.
1: var http = require('http');
2: http.createServer(function (req, res) {
3: res.writeHead(200, {'Content-Type': 'text/plain'});
4: res.end('hello world\n');
5: }).listen(8000, "127.0.0.1");
The above program will create a HTTP server which will listen for an event in port 8000 at http://127.0.0.1. Let me save this file as server.js. To execute this program, open up Windows command-line and enter the following command:
node server.js
Let's navigate to http://127.0.0.1:8000/ in a web browser that show a web page which shows the text "hello world".
Node.js on Windows Azure
Windows Azure is a powerful cloud platform which provides the first class support for Node.js which lets the Node developers to build and deploy Node.js apps onto Windows Azure. IISNode is the enable component of Windows Azure for Node.js apps.The blog post Top Benefits of Running Node.js on Windows Azure provides the major benefits for deploying Node.js apps in Windows Azure. For more details on Windows Azure support for Node.js, check out the Windows Azure Node.js Developer Center.
Windows Azure SDK for Node.js
The Windows Azure SDK for Node.js provides the full fledged support to develop and deploy lopeNode.js apps onto Windows Azure. With Windows Azure SDK for Node.js, you can deploy Node.js apps onto Windows Azure as a Web Role which will be available for scalability provided by Windows Azure. You can download the Windows Azure SDK for Node.js from here. The current version of the SDK is 0.5.4.
Windows Azure PowerShell for Node.js
The Windows Azure PowerShell for Node.js is a command-line tool that allows the Node developers to build and deploy Node.js apps in Windows Azure using Windows PowerShell cmdlets. Using Windows Azure PowerShell for Node.js, you can develop, test, deploy and manage Node based hosted service in Windows Azure. For more details on Windows Azure PowerShell for Node.js, check out my blog post Windows Azure PowerShell for Node.js. The following resource will provide all details about the Windows Azure PowerShell for Node.js
- Windows Azure PowerShell for Node.js Cmdlet Reference
- How to Use Windows Azure PowerShell for Node.js
Using Cloud9 IDE for Building and Deploying apps in Windows Azure
Cloud9 IDE is a cross-platform, browser-based development environment for JavaScript and Node.js apps which can be used for developing and deploying Node.js apps in Windows Azure. My blog post Building and Deploying Node.js Apps to Windows Azure using Cloud9 IDE
Here’s a few more links for Node.js and Windows Azure
- Windows Azure Node.js Developer Center
- Glen Block’s (Senior Program Manager - Windows Azure SDK for Node.js) Blog
- Anode => Windows Azure + Node.js
- Interview with Glenn Block Talking About Node.js on Windows Azure
- Node.js–How to use Node Package Manager (npm) and Underscore
- My GitHub repository on Node.js on Windows Azure
- Developing and Deploying Node.js Express Web App on Windows Azure
- The Node Beginner Book
- Useful Node.js Tools, Tutorials And Resources