 Yeah, so welcome to the session So this talk is about Jays on windows no days on windows Sam and Raj that shaker. I work as a So So I'm pretty sure they're having you know a number of node sessions today, right? So I don't suppose I would have to talk about what is known in all that stuff The basics how many of you here have not heard of not What three of you Yeah, so I mean very briefly node.js is basically a JavaScript based Server-side framework, right? It's a it's a it's a framework that allows you to use JavaScript as a programming language to create Network applications not just web applications any kind of server-side application So this session this talk is about how node.js is a first-class platform on windows So node.js traditionally Historically it has been developed on Nix platforms right on Linux Unix So it basically uses Chrome's V8 JavaScript engine to actually execute The JavaScript itself so a fair amount of work was done to basically support node as a first-class environment on Windows as well, right? So that's what we'll be looking at in this session So so You know briefly that what we look at is we look at you know How you can do node.js development on Windows? What kind of tooling support? What do you need? How do you set up? How do you get started? We'll see you know How you can host node applications on internet information server in IAS? How can you create your applications post it and how does that architecture work? And finally, we'll also take a look at how node is a supported platform for the cloud It's for Windows Azure. This is basically Microsoft's cloud platform how you can create server-side applications web applications, which you know, which can scale to you know However, you have your traffic, you know, your load profile is so basically the Windows Azure is a cloud platform for from Microsoft and now node.js is a first-class supported server-side application development framework for node as well, which means you can create node applications and deploy them on the cloud on Azure So with that let's let's get started You know what it takes to get set up on on Windows, right? If you want to develop node applications So I'll probably not spend a lot of time on on index and probably just show stuff for you So basically on Windows, there is this tool called as the web platform installer called web.ti You can just look it up. The web platform installer is basically a tool that allows you to install various kinds of web development You know Development tools, development software on your machine. So you can just go get it's like a package manager that you might be familiar with There only last kind of operating system, so very simple to that only there's a nice GUI So you can load the web platform web.ti installer, list all packages You can select what you want it automatically figures out, you know What are the dependencies are needed for installing that package and then installs that right and subsequently when there are updates You can install your updates as well through web.ti. So node.js is available for Windows as an item It's basically distributed through web.ti through web platform installer So that's one way you can get it. So let me quickly show you what the web platform installer looks like. So as soon as you install it You'll see something like this So this loads the you know the package list not on the internet but the idea is You can just you know search for node and the node package is listed. You select, you know that the particular package you can install I mean, it's a very painless process. So as soon as you search it shows you that node.js is available you go ahead and obviously I've installed it already So you hit add and then install it and install it right. So that's straightforward as it can get So so that's all there is. So once you once you install node, then you know It's pretty much available on your on your machine. So you know, you can go ahead and hit node And that's it right. So Node is running there for you. So five plus one Not a good idea. So that's your that's your repel, right? So that's how you get node. So When you when you install node using web.ti, you obviously get node. You get npm the node package manager Um, and you also get support for node in is that's called as is node Which is basically a module in is that enables you to post your your web applications for your node applications in is Um, so let's let's take a look at that. So what all can you do with node on windows, right? So So let's uh, let's go ahead and create a Create a create a very simple hello world app in on windows, right? So I'll just go here js So I'll just create a hello world app Or maybe Right. So What I'll do is I'll create a a file here. So I'd say is sublime Uh app.js Probably have to say start sublime app.js So folks who have done node development probably, you know, this will look very very familiar. So I'm including the the The htp module and then I say create server and I pass my callback function which takes a request and a response Write all standard node stuff Um, probably I'll put that into a so variable here. Probably I'll say a response dot Write head return a hit 200 status code. I'll say content type is text slash html I'll probably You know put my message here. So I'll say h1 hello node or something So that's my markup I'll probably end that This thing then I'll say server dot listen Uh one two three four localhost And I'll probably print a message to the console. So server listening on localhost colon one two three four okay, so That's it. So we've built a very simple Node app so I'll say node app.js. So that's it, right? It's as straightforward as it would do in in linux or anywhere else So now I can just go and say htp colon slash slash localhost one two three four And hopefully you should see hello node, right? So that's about it. So, uh You know, this might this might seem like a you know, not not a big deal But the fact is the entire code has been ported to to windows and it's uh, it's basically Taking advantage of all the native windows capabilities, right? So the io completion Mechanics how it works in linux is not the same in windows. So it's it's a it's actually a complete You know the the pieces which bind to the operating system have been ported completely windows. So So in fact, obviously it's all open so you can go take a look at it um, so that's The first thing I wanted to show you Uh, okay, so that's that's hello world, you know, maybe a slightly Uh non-trivial example here. So I have a somewhat cheesy looking game here that I put together sometime back Let me just run it and show you what it does Um, so this is a this is a node app which uses socket IO So it uses socket io to how many of you have heard of socket io? about four of you So socket.io is basically a framework that has been built on top of node Which allows you to do real-time communication with node, right? So what do I mean by real-time communication? So typically uh on web applications, right? It's like HTTP based request response model. So if you want to send a message to the server, you make a request So the process is it sends the response back close the connection. So this is how it typically works, right? Even when you visit a web page The browser is basically sending a barrage of your request the server key is responding to all of them And that's how you navigate to a page, right? So all the requests for your html, prejs, pre css, pre markup, all of that goes and comes back So that's what that's how HTTP works. It's not a persistent connection, right? You request to respond to a signature Uh, but what but there are scenarios application scenarios where we want the connection to be persistent We want to open a connection to the server and uh And you want the connection to stay alive for the lifetime of the app, right? And you want to be able to send messages, receive messages for example, you know, the canonical example for real-time communication is probably a chatter Right? So you have a chat application There are different people locked onto the chat server as soon as it's in the message We want that message to be visible on all other clients as well, right? So here you can't use HTTP to implement this but that would essentially be a kind of a hack, right? So you would uh So how would for instance, uh a particular chat line be notified of it where a new message has arrived from another user? How would you be notified of it? It's with just HTTP you would have to resolve the hacks you would have to uh, Maybe you have to continuously pull the server, right? You have to keep asking the server Do I have a new message? Do I have a new message? The server will return a message if it has one There is no message and server says no no message and then it goes back The polling site right it keeps on pulling and there are other hacks as well In fact, the the talk that happened through this on the other room was about real-time communications on the web and you know, uh Different options were considered so there was something called a scommet Which is again a technique for simulating persistent long You know persistent connections using just HTTP. There's another technique called as long polling. There is a You can use hidden iFrames, which never I mean, there are like many hacks, right that that's simulated real-time communications But they are all you know, that's what they are. They are all hacks. So web sockets is a is a new html5 spec Which allows you to do real-time communication With you know with native support in the browser like the browser supports web socket You can do you know, it's pretty much a native tcp socket So you can open a native tcp socket to the server and then you can and that connection is going to stay alive and you can communicate with on that software socket.io is a Is a node js You know framework which has been built on top of node js where basically the idea is you can do this real-time communication in your web applications The the real value add that socket other brings to the table is It has support for legacy browsers as well, right? So so for example, if you're using a modern browser which has support for web socket Then socket.io would automatically use that right because that's the most high performance native, you know Not real-time communication technology that can use On the other hand if you're using an older browser, which does not have support for web sockets Then it would basically downgrade to using one of these other techniques that I was talking about Right, it might use polling or it might use, you know, even flash or silver light Whatever is available, right? It will basically figure out what is the best technology available and you use that That's what socket.io does. It's a very popular framework in node js You know in the community, so this this app is basically uh, you know a game which was built As you will see a kind of gc-looking game It's running on port 3000. So I'll say localhost so The idea is I don't know player one something I'll just put that there And open another window and player two So the idea is, you know, I can I can just move this thing here and you can see that, you know, when I move this thing over in one window It moves another window or so uh So that's real-time communication for you So all this talk was to move this little ball around So, you know, but the point of this demo is that uh, this whole app is running on node js and socket.io And the communication like when when these little cannons are Little tanks are moving around their positions and the positions of the bullets So all of that is being communicated in real-time uh through WebSockets in this case, I'm using IE 10 which has support for WebSockets Uh, and you can see there's a lot of logging happening in the in the background But the interesting thing is I built this app, uh, a long time back probably Some two three probably more than that probably four or five months back and at that time node js was not supported on windows So I wrote this app completely on one tool in us and I had built it along with the core of mine and uh And that's it. So uh yesterday when I was preparing for this session I was wondering, you know, it would be nice if I can show the demo of that But I wasn't sure that it'll work at all Uh, but I just thought I'll give it a shot. So I uh, so basically what I did is in fact, I can show you what I did Um, let me just create a mkdir 300 V2 something right um So I just went here and I said npm install Socket.io is it socket on it? Let's try. Yeah So that's it. So, you know npm is the node package manager tool that you install stuff So that is available for windows as well. Then I installed I think it uses expressjs as well So I said npm install express and It went ahead and downloaded and installed expressjs Uh, so you can see that, you know, the node modules are there express socket.io Everything has been installed and then I simply copied the source code that I had my uh scripts and app.js And put that here And that's it. So I said app.js Uh And we are in action, right? So that that works perfectly fine. So that's all I did So that tells you the fidelity of the porting, right? It works Exactly. I mean, you don't have to make one change to source code to make it work on windows Which is of course the goal So So that is the second thing I wanted to show you a slightly non-drivial example. Um, all right In fact, uh, in fact, let me show you how you can do expressjs as well So let me create a mkdir hd Maybe I'll create Start subline app.js. Maybe here I'll say require Uh express equals require of express Um, what is this in tax express dot create server Uh function of request comma response Here I'll probably say response dot send Hello expressjs right And uh, I'll probably say express dot listen of 1 2 3 4 So slightly easier, uh, uh syntax. Obviously, I don't have expressjs here. So I'll say npm install express and uh You've got installed. So let's try. So I'll say node app.js and through the network Uh, I think it's start, right? But as I say scenarios like this, I have uh, it's uh Get get confused with all this in taxes and uh, I need to save our server equals express dot create server And I say server dot get Are we good? This is listen after all having much luck No Sorry I'm not taking listen is it? I have to say server Hey so localhost 1 2 3 4 And it says hello expressjs right so So here obviously I've used uh expressjs to very bare bones web application But obviously you can use the full expressjs framework to set up your roots Set up your static folders your views, you know, you can use jade Whatever you're used to using so all of that is first-class support is available in Uh, in windows. So this is just plain development, right? That is how how you can use node to develop your applications on windows, right? You can use any edit your favorite editor go ahead and do it Next thing I want to talk to talk about is how you can host your node applications In this case, I was hosting node directly like I was running node.exe passing app.js and it worked Uh, you can Host your node applications in IIS, right? So IIS is a full-fledged Uh, you know production industrial strength like server, right? And it comes with a whole bunch of features and capabilities So what if you want to use the power of IIS and still develop your web applications with node? So that that's where you can use uh use is node. So is node is basically a module So is supports this extension mechanism called as a module, right? So you can extend the web server itself by creating modules which provide additional functionalities basically If you are familiar with ASP.net HTTP handlers, it's very similar to that So you can create a so basically is node is a module that has been created For is which basically Brokers connections between your clients and your node applications and it does something more than You know, just launch node it actually as you can think this Diagon here. So you have You have IIS, right? Forget about this retro workable business Just focus on this IIS box. So you have IIS and IIS basically has a native module called as IIS node which manages a set of node processes So you would create your node application Post it inside and would deploy inside IIS and IIS will take care of launching the node processes to actually run your app And the interesting thing here is it can launch more than one node processes And it can basically load balance your request across those node Across those node process. So let's say, you know, uh node this particular process This is handling one particular request and you receive another request It can basically hand it off to another process in parallel So, you know, your request get suitably load balanced across multiple node processes So maybe you can take a look at, you know, what that what that looks like Um So basically here, let me just open Inet NJR, which is basically the console that you use to manage IIS I've basically installed a set of samples here. Maybe first I'll show you A simple node app that I put together here Server.js again is It's the basic, you know, hello world example that you see on nodejs.org There's only one difference and that's process.en the listen listening port here Right, I say server.listen and I give process.env.port. I don't explicitly specify a port and what is the reason for that You saw in the diagram that you have IIS Inside that there's a module called IIS node Which basically manages the incoming traffic to multiple node instances, right Uh, so what port do you listen on? So if I write one two three four, I have three instances launching on That same app Basically, you will have a conflict, right? You can't have multiple TCP sockets being opened on the same port The operating system is going to complain. So here basically what happens is with IIS node the communication between IIS and the node processes Happens through named pipes. So it's a basically an inter-process communication mechanism on windows called named pipes It uses that to communicate between IIS node and the node exes. So it's not a TCP TCP port. So it doesn't use You know sockets and TCP connections to communicate between node and the IIS Obviously the browser and the IIS would work as it always has worked the communication between this and this is different So that's why you have to specify this that's the only point of difference if you want to hold it inside Inside IIS There's another thing that you might want to look at and that's the web.config file This basically provides one entry and that is basically it maps all requests that come in for a .js file to This particular module called IIS node. So basically what we're saying here is We are instructing IIS to look at all requests where which end in .js And these HTTP works a star means all works that is get, post, put, delete everything and We're saying hand it off to IIS node that particular module. So that's why that's what causes IIS to actually take and run the .js Otherwise, it'll just download the .js, right? Um, so that's it. So with these two things you are you're all set. So what we can do is we can go ahead and browse it uh, so here you can see that You know this this is basically just you know localhost slash hello IIS node This is basically a virtual folder that I created on IIS and it's running it's running the node application, right? And in fact, if you see the process manager and all you will notice that There's a node exe running. So you see that node dot exe So that was launched by IIS In fact, let me try launching process explorer and show you that That's what is actually happening. So do you see that maybe I'll also So So there you can see that, you know, W2WP is basically the the worker process for IIS And that has launched node dot exe and that's where your app is actually running the communication between these two is happening through name pipes so So that's how applications are, you know, how you can run applications inside Inside IIS There is a if you go to the IIS node, you know implementation. In fact, the IIS node implementation itself is open source So you can go to github search for IIS node. You can look at the source code for that native module that you're talking about You can see how it has been implemented. So here are a few samples that are available Obviously, this is this is a hello world here Now the interesting thing is with IIS node, another thing that you get free out of the boxes support for debugging Which I think is really really cool So here I have a I have a hello world sample. So this is the code Nothing nothing new. It basically gives you some diagnostic information Uh, but what you can also do is you can debug this in webkit based browsers. So for example, what I can do is I can So I can go ahead and Launch my url like this. So the url here is All right, so I'm sorry. My zoom it is not working. But here basically the url is localhost node hello world. That's my Hello world slash hello.js. That's my url for the app I can simply say slash debug and in webkit based browsers, you will see the debugger actually launching So what I can do is I can go and hit set a break point here And then you know navigate this from another tab or another browser even so for example, I'll open this in IIS And you can see that You know the the thing has been hit. So, you know, I can inspect the objects here. It's basically a full debugger here Right, I can do that. I can step through. I can say f8 Uh, f8 doesn't step through continuous. So I can say f10, right? I can step through each line Right. Complete debugger is available when you use IIS node, right on webkit browsers, which I think is simply amazing All right, so that's another thing that you can do with uh with IIS node support in node Uh, and then there's support for logging as well So basically if you have any code which says console.log that is access Basically all the console.log gets routed to a file which you can access. For example, this is another um, so here I can I can So that's the that's the logging sample now. There is this another url here that I can visit So the url here is Again It's probably not very visible there So we are here is uh node slash logging slash hello.js dot logs slash zero dot txt one dot txt and so on So whatever console.log is there you can access those through that url And if you want to put authentication or something you can do that on that support again, right? So that the logs are not visible to the whole world Uh, so but the idea is all that is accessible another interesting thing here is they're logging on the you know What that port is and you can see that the port looks a little weird there, right? It says slash pipe and all that So that's basically the name of the named pipe So that kind of proves to you that it's not using TCP So those are the few things that I wanted to show you on the uh on the is front Um, sorry There's only three minutes left And then questions and then questions. Okay, all right. Um, so I was a little confused when he said only three minutes left. Okay, so the last piece that I want to talk about was uh Was on the on the azure Support in node right so we saw how you can develop with node on windows You can develop debug post on windows how you can post on is uh, and you know is is a fully supported Platform for posting in node apps the last thing i want to talk about is how you can take your node app and deploy them on Windows azures. How many of you here have Not heard of windows azures Uh before this Okay, not bad most of you have a lot of it. So so for the benefit of people who haven't so windows azure is basically uh, so Have you heard of amazon web services aws? Right. So this is basically microsoft's offering cloud offering, right? So this uh, basically your cloud applications can be created and posted on uh on azure You can scale your applications up that is basically you can scale horizontally your applications are depending on your load You can scale it down and you know all the benefits of cloud, right? So this is microsoft's cloud platform Now you can put node applications on that So the idea here is you know, this is typically the the flow so you can create your Hosted service the hosted service is a term that applies to windows azure That basically is your application. You can create develop and debug your applications locally Uh, and you can uh, you know simulate your most azure hosting environment in the local emulator Uh, so azure brings in some you know some features, right? So like you can use your storage service azure storage service, which is you can have table storage You can have q storage. You can have a block storage. So, uh There is an npm package that is shipped for load So you can simply say npm install azure and then you basically get a bunch of javascript libraries Which allow you to interact with azure storage services for example, right? So Uh, so you can you can work with that and you can debug it locally using an emulator So there is a dev fabric. It's called basically a local emulator Which is like a it's like a small version of azure that you can run on your machine, right? And you can debug your applications on that You set configuration settings. So being a cloud platform You have to sign up on on windows azure. So you go to windows azure.com You sign up for a for an account with uh windows azure And then basically your account will have something called as published settings It's basically an xml file which has information about who you are And you know, what is the information that it's needed to publish your app to the cloud So you get that imported to your machine and then you deploy it. So Let's let's quickly see what some of that stuff looks like Um, so when you go to web p i web platform installer and have add support for, uh, azure node or your machine one one of the things that you will get is a power shell command commandlet called as uh the windows power shell, uh sdk for Windows azure power shell for node js This is basically a set of command line tools which you can use To create your app windows azure app locally to launch your regulator and uh, basically, you know, do your development On your on your machine locally and then finally publish it to the server as well So let me quickly show you what that looks like um That will help So oh that is that makes somewhat better. So I'll just go to this thing. I'll go here. I think, uh, js slash node js What do I have here? All right, so I'll create a directory called hello azure Uh, in fact Let me not do that The the command line tool will actually do it So the first command that you will use to create an azure service is something called as new New azure service right and you give a service name. So I'll say hello azure So basically you'll notice that uh current directory update So we were in node js So it has created a directory called hello azure and it has created a bunch of files that it has done a cd into that So if I just say start dot You can see what all it has created. So it has created a bunch of files here uh, so You know, these are basically the configuration files that you need to um, you know To package your application and deploy it to uh to windows azure So your service configuration, for example, will have information about you know, what are the roles that you have in your in your application How many web roles how many worker roles your service definition will have information like how many instances do you need? What kind of instances like, you know, I want three web servers running my web applications and they need to be there are different, uh, you know VM sizes like extra small small large and so on so you can give all those configurations in that And both together will be used package and application and deploy to windows azure, right? So just doing new, uh New azure service results in that particular structure being created. So now in this azure service, I can create multiple Uh kinds of applications So in windows azure, there are two kinds of what are known as roles in fact There are three kinds of roles Worker role and VM role. So let me talk about web role and worker role. Um, so basically If you want your application to be deployed on IIS that would typically be created as a web role Right now all these roles are just uh, you know, uh application level abstractions Windows azure itself doesn't really care about all that right windows azure This is a really intelligent virtual machine manager. That's what ultimately boils down to But for us as web application developers, we we get to choose, right? So whether if an application wants has to be hosted on IIS And you know, you want to leverage all the power of the is then you would typically create a web role, right? And if you uh, if you want to do your own thing, so for example, I want to run a bad job, right? That needs to run at a certain time. It needs to be scheduled or whatever the case is Then I would typically go for a worker role or, uh, you know, as in this case I might even kill the node app, right? And I want to post node run node separately I don't want to run node inside is for whatever reason in that case I would go ahead and create a worker role and set it up to run node.js as soon as it starts So here let's go ahead and create a web role. So I'll say add Uh, azure node web role And I'll just run that So it does some things and uh, if you notice here Now there is a new folder created Uh, called web role one. I could have actually given a name I could have said add azure web role and the name for the web role And if you go inside that web role, you will notice that it has created a server.js and a couple of web config files And in bin you can see that some msi's and and so on are there the node.exe is there So these are node application. IIS node installer is there. This is set up IIS node on IIS Uh We see the redisk is basically visual c++ uh runtime and uh a batch file to set it all up So what is there in server.js right? So let's go ahead and uh, let's quit magnifier for a second. Um So let's open server.js and take a look So again nothing magical. So just a regular hello world. Um, say hello IIS node We'll say on azure something right all right, so Now that I've created a created a web role and I've created my app Let's say right. I did all my coding now. I want to deploy this now I want to run this locally in the azure emulator, right? So how can I do that? So what you can do is you can say start azure emulator I can launch And I hit enter so now essentially what is happening is it is setting up my Emulator locally that dialogue that you saw was basically firewall configuration for for my local machine So we typically want to say allow Um, so here you can see that the application has run and it says Now in the system tray you can see a little icon here. So that is basically uh, uh the emulator the process for the emulator for managing the emulator So you can actually go and say show compute emulator ui Uh, and it'll show you the So here there is there is a little azure is my service inside that I have my web role So I can go here and click here and it'll show you the you know This is like a console for my And there's only one instance in this case right if I were to add it like five instances for example You would have seen five road instances all of them running my application right So this is this is how you set it up locally So if you want to locally, you know create your app in the local emulator That's how you can do that right just as I added a Web role you can definitely go and add a Worker role as well. So, you know just you can say uh add azure node Worker role right and you can give a worker role name and then your worker will get set up right and there you can Go and put your js and that will work as well. So let me show you another example here. So let me just In fact, you can say shut down. I think shut down It's top azure emulator. So if you say stop azure emulator, it'll basically terminate or you can go and exit from the From the listing as well. So now it has shut down both of them And they terminate that so I have another demo here a slightly non-trivial one Which actually uses the azure storage that I was talking to you about earlier So let me just go ahead and Start the emulator For that particular application. So this is basically an application which tries to simulate stop codes. So, I mean It's not obviously real. It just cooks up some numbers for some companies um So let's see what happened here. So both the so there are two roles here the get codes is basically the Is the is the web uh the web worker role? um Which basically dynamically keeps inserting rows into my uh into my table So I'm using azure table storage to actually store the data and this is my web application. So For some reason, we're not seeing the Output here. We're having some demo issues Uh probably not very important, but let me quickly show you the code what that looks like So stop code. So this is basically the uh the code for um, you know inserting data into a table storage. So So you can see right at the top that I've said, uh azure equals require of azure. So how did I get that module? I simply went and said NPM install azure you can do that And then your azure module gets added to your application And then you can obviously require it and that's basically an api for handling your Table storage block storage q storage and so on. So here, you know, this is how you create a table service You get a client and then you create actually a table um And then once that completes you can go ahead and set up your set up your information So what I've done here is I've done a set interval and I call generate data for Every certain milliseconds, which is code. Uh, okay every five seconds So every five seconds I call generate data and in generate data Go ahead and cook up some numbers for some companies and insert that into Uh into that paper. So very straightforward interface, right? So create a table add rows to it and you're done Likewise on the other side of things so on the on the web application the show quotes if you notice here, uh index.html Um, what I do is I basically call a server side service. So I have a json service If I go and open server.js, you will notice that, uh I basically get a reference. I basically use azure get a reference to that table and then I create the server here and uh Every time I get a request What I do is I make a query to the table azure.table.com it has its own syntax You can go in and look it up. I get that table. I provide a you know, uh A certain query basically I'm interested in quotes that have been generated from now Or maybe in the last uh 10 seconds And then I get the data and write it to the to the client, right? In fact over here, I basically stringify that information right to the client You know the client I basically take it and show it on the on the ui which for some reason did not work Uh, so so this was basically a slightly non-driven example where I was using some azure storage apis to Call them from my node application So with that we kind of Come to the end of the session. So this is all the stuff that I was talking about Uh, so this is the module that you can add you can say npm install azure and you get uh support for You know the api for interacting with windows azure storage For that we kind of Have done with the session. So if you have questions, we have about three minutes Uh Any questions on node on windows stunned silence Uh, yeah, I guess the the one takeaway from the from this whole session is that node is now supported first-class platform on windows It's uh, you know a lot of work has been done in order to get that support When I say first-class it means you know, a lot of work has gone into into ensuring performance So you get high performance, you know, even that's what node is all about right high performance Eventative so that works, you know as it is designed to work on windows as well Now as well as or not better than you know any other platform. So With that, I think we're pretty much done. Thank you