AZR216 – Node.js and Windows Azure

Node.js is a platform for building fast, high-scale applications in JavaScript. Node.js uses an event-driven, non-blocking I/O model that allows developers to quickly and easily create everything from simple websites to high-scale real-time applications. In this session you will learn how to build, deploy, and host your Node.js application on Windows Azure.

Presented by Nathan Totten

Disclaimer: These are conference session notes I compiled during various sessions at Microsoft Tech Ed 2012, September 11-14, 2012.  The majority of the content comprises notes taken from the presentation slides accompanied, occasionally, by my own narration.  Some of the content may be free hand style.  Enjoy… Rob

Kicking off.  Nathan Totten – Evangelist, Windows Azure. ; This is a Level 200 session, so it will be fairly brief with some code samples.

Introduction to Node.js

Node.js – is an open source/open framework built on Google’s Chrome engine.
JavaScript on the server… Event drive I/O server-side JavaScript. ; Runs on a single thread..Not thread based, therefore small heap allocation. ; Efficient and scalable.

All operations are essentially queued, and actioned by the single thread. ; The thread can’t afford to hang!

Good At

  • Realtime comms/quick chatty interfaces
  • REST interfaces
  • JSON web services
  • Client oriented web-apps/UI

Bad At (or not great at)

  • Forms over CRUD (can be done, but maybe not the best choice)
  • CPU intensive processing (don’t render media, images.. too intensive)

Pros

  • JavaScript – common language
    • Not a lot of standardization, different styles
  • Clean API
  • Simple concurrency model (is it concurrent??)
  • Idle connections cost next to nothing
  • Modular

Cons

  • Not a lot of standard framework inclusions
    • No particular testing framework etc
  • Young, still developing
  • Bare metal.. not for the inexperienced.. not great IDE support etc

Application Frameworks

  • Connect
  • express
  • geddy
  • (fab)

Node.js on Windows

Native build on Windows. ; Ported from Linux, can host Node processes on IIS with IISNode, which gives the benefits of IIS. ; Modules which work on other platforms will work on Windows. ; Contains package manager support from the commandline.

Node.js on IIS

  • Process management
  • Access to logs
  • Side-by-side with other content
  • Scalability on multi-core
  • Auto-update
  • Minimal node code changes
  • integrated management experience

On to… live [Demo]

Showing how to implement a HTTP server variable in Node.js script. ; Can be self hosted? ; Implements a web server (single threaded?). ; Command line tools written in Node.js. ; Windows Azure tools included.

Most Node.js/Windows Azure functionality can be developed without visiting the Azure control panel page. ; Supports inline GIT support – interesting. ; A bit of deployment pain as access is denied. ; Heading to the Azure Control Panel after all…

20120912-172743.jpg

20120912-172751.jpg

Using the command line to invoke the server side GIT repository to create the appropriate folders.  This might be tough for non-GIT users to follow.  TFS users looking baffled.

Packages being pulled down (like NuGet), but on the Azure server side.  Site is now up and running.  Deployment history is tracked on the Azure side.  This allows rollback functionality.  The GIT integration is quite nicely done.  Somewhere Ted Buchan is grinning.

Deployments look pretty impressive, but a knowledge of GIT would be most handy.

Debugging Node.js

There’s something called a NodeInspector.. It runs in a web browser (but not Internet Explorer), so now we’re loading Google Chrome..  ironic.  It’s a matter of putting the Node server into debug mode.

NodeInspector.. why does that remind me of Inspector Gadget?  Go go Node [thing]!

20120912-173711.jpg
Node Inspector

Yes, you can also remote debug assuming the correct ports are opened.

Node Supervisor

Watches files for changes..  Otherwise, to void the cache, you’d have to restart the Node server.  Installed as a package through command line:  npm install node-inspector –g

Socket.IO

Enables poling, web socket style functionality.  Installs as per command line.  Works on almost any browser, real-time communication requires long polling or web sockets.

20120912-174553.jpg
Socket.IO supported

As Azure is running currently  on Windows Server 2008 R2, and that only IIS 8 (Server 2012) supports web sockets, as a consequence the current Node.js support in Azure needs to use long polling (as mentioned before).  This will be changed.. soon.

Demo fail – hardcoded localhost in the socket.io code referenced.  Live demo means audience participation.  We’re starting to trend to a close….  Hilarious user input into the live Node.js server.

Head to github to find out more – this is open source stuff.

So I have an event to go to between 6pm-8pm so I’m going to have to wrap up early.  This has been a pretty interesting introduction to the world of Node.js on the Windows platform.  There are undoubtedly some interesting uses for this approach.  It will be one to watch.

/R

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.