Last week at the Microsoft Build conference & this week at Microsoft’s Ignite conference, I presented short express talks / theater sessions on using Node.js to run a web application that integrates TypeScript, AzureAD, ADAL & Office 365 APIs in a neat little demo. If you missed it, you can grab the code from this project in github as well as watch this video of the running demo .
What I find so cool about this approach to building web application is that they can run on any platform with no code changes. I developed the web application using Visual Studio Code on my MacBook Pro where I also tested it, but I also ran it with zero code changes on Windows 8.1, deployed it to an Azure web app & to the Raspberry Pi. The only thing I had to do was tweak the IP of the device in a configuration file & update the reply URL in the AzureAD application to redirect back to the correct host.
When I show this little demo I usually get a bunch of questions. One is what you need to do this. For my demo you only need to buy three things: the Raspberry Pi 2 for about $40, a Wifi USB adapter for about $10 & a 32GB microSD card for about $15… all told, about $65.
The other question I get is how do you do this once you get the hardware. There are a few different things you need to do.
First step, you need to get an OS on the microSD card & then install Node.js on it. I’ve written about that in a previous blog post here: Setup Node.js on Raspberry Pi 2 B .
Once that’s done, you need to get the code for the Node.js project on to the microSD card. There are a few different ways you can do this:
- Connect to the Raspberry Pi via SSH and use git to clone your project to the device… make sure you run
npm installto get all the packages the app needs
- Connect to the Raspberry Pi over SMB file share from your laptop & XCOPY the project & package dependencies over to the device’s microSD card
- Copy the project & package dependencies to the microSD card by connecting the card to your laptop
Personally the first option is the easiest, but it can take some time to download everything. The last option is pretty easy, just gets to be a pain to move the card between the laptop & Raspberry Pi and then boot the Pi.
Last but not least, if you are building an app like what I’ve done in my sample that uses AzureAD for authentication, you will need to get the IP of the device and set it in a configuration file as well as update the application in AzureAD so once the user logs in, they are redirected to the website running on the device.