Technology

Setting Up your Mac for Node.js Development with Azure

One of the absolute best parts of working in today’s web development world is the choices you’re now afforded. Long gone are the days where your choice of technology in one aspect of a project would dictate the entire stack. Want to use your Mac Book Pro? Go for it. Want to use javascript on the server, as well as the client? node.js has your back. Looking for a cloud provider to host your project while your business grows? You can be up and running on Azure in less time than it takes to brew a good cup of coffee.

For a recent project I was working on these are the tools that worked best for what we were looking to accomplish. In the next few blog posts, I’ll detail how I set up my dev environment to accomplish these tasks. The first post takes us from scratch to a default express.js installation running on an Azure Web site.

Prerequisites

Before going through this, I’m going to assume a few things.

  1. You’ve already installed Node and NPM on your Mac
  2. You’ve already installed Express.js via NPM
  3. You’ve already signed up for a free trial Azure account

Once you’ve got these ready, your good to go.

Connecting to Azure from the command line

There are two ways to set things up in Azure, the web, and the command line. Since I try and spend more time in Terminal than a web browser (less distractions 🙂 ) I tend towards using the command line. Microsoft has made this relatively painless with the Azure CLI NPM package. To install it, just run the command:

npm install azure-cli -g

Once that installs, you have a very nice and useful set of commands to interact with your azure account. To start, you’ll need to get your publish profile by issuing the following command:

azure account download

Which will open your browser and have you log into your account to download the profile. Once you log in, it will download and then you can start using it by running:

azure account import [path to where you downloaded the file]

Now your ready to go 🙂

Creating your new Azure web site

Now that you can interact with Azure, let’s actually do something. To create your a new azure web site run the command:

azure site create [new site name] —git

This will create you a new azure web site, and also set it up for git development while also setting up the current directory to be a git repo with the azure remote entry already added.

Creating the default express.js web site

Creating a new express site is down the same way as it always is, running the command:

express

After it runs, you can make sure it runs locally by running:

npm install

And launching node:

node app.js

After ensuring that it is running locally, by pointing your browser at http://localhost:3000 you are ready to push your creation to the cloud. To do this, all you have to do is commit it to your local git repo

git add . git commit -m “initial checkin”

And then push it to the azure remote repo:

git push azure master

And that’s it, you’re live in the cloud! To show your new site in the browser, you can use the CLI shortcut

azure site browse

Conclusion

The ever-expanding world of web dev tools is an unending list of possibilities to make your life as a developer easier. Never has it been easier to mix and match tools and practices to find what works best for you and you project.

This post originally published at blog.4mkapps.com

Leave a Reply