For reasons that will not yet be unveiled I decided to have a look at Node.js yesterday for the first time in almost a year (I did a school project in Node.js as my final project with another student). And I got curious, how easy would it be to set it up on Azure? We used Heroku last time, and it was fairly straight forward. I have however taken quite a liking to Azure Websites, so I decided to give it a go.
I did like I did on my last Azure Websites post, Deploying from local git repository to Azure websites (w. video), with a few changes.
This time I didn’t use a local repository but a remote one. And this was a Node.js application.
Let’s do this!
First, if you don’t have Node.js, go ahead and install it. You can grab it from here http://nodejs.org/ .
After install you might want to grab express.js (web application framework) as well, so do a npm install express –g (globally), create a directory mkdir NodeFun , and install express there as well. Honestly the locally/globally thing with express confuses me- but I was told to do both. Then do a npm install in root folder and watch the magic happen.
node app should run the app, so if you go to the browser localhost/portnumber you should see the site spinning and purring like a kitten.
All good? Great! Go to GitHub and create a remote repo. Open your favorite gitbash shell and do a git init in the root folder. You now have a local and a remote repository. Set the remote repository with git remote add nameForRemote https://github.com/UserNAme/Repo
Do an add and a commit but wait with the push
git add .
git commit –m “First commit”
Go to Azure Websites, create a trial account if you don’t have one.
Select New, Compute, Web Site, Custom Create
Give the site a name, select region and database (if you have one)
After you click ‘next’ you get to select source control for continuous deployment.
Choose GitHub and authorize Azure Website to access your account. Then select the repository it should be watching for changes, and the branch.
In the background Azure Websites provides a service for us that listens to changes in that repository on that branch, and whenever you, or anybody else, pushes to that branch the service picks it up and kicks of a new deployment with the code on that branch. Here is a diagram I made with love in Illustrator for you.
If you go to the web site url at this point you should get this:
This is because we haven’t done our first push. SO let’s say we were lazy and decided to use the master branch as the deploy branch, we have added and commited, so the only thing left is:
git push nameForRemote master
You should now get:
Do some more changes and some more pushing, say- add bootstrapper for responsive design and add a fantastic button after battling Jade and get this:
Awesome. I know. But this is also just a quick try for Node.js and Azure Websites, and later this week I’ll tell you more about this mission- and there will be code 🙂
This took me 5 minutes on the slowest WiFi I’ve had in the US, so you should be up and running faster than that.