Sails sailing seamlessly on Azure Web Sites

Learn how to deploy SailsJS applications seamlessly on Azure Web Sites with continuous integration. Step-by-step guide to hosting Node.js frameworks.

2 min read 379 words

There are lots of frameworks for web development in Node.js. Many of them are pretty cool. I pretty much like SailsJS, and I've also worked on it recently.

Now, when it comes to hosting, I love Azure for various reasons. It's especially awesome when it comes to websites. You do some experiments and throw it towards Azure, and that's ready for the world to check out. My many experiments with F# and Web are already there.

Recently I was talking with a friend about SailsJS, and the discussion kind of stuck at the deployment part. As it's having a kind of manual process involved. It's never an issue to fire a few commands, but why should I waste a few keystrokes when that can be done by Azure?

Always a fan of continuous integration and continuous delivery mechanisms

I searched Google to find out if anyone had done this before. Results showed a couple of examples, but all with spinning up a VM on Azure and hosting an application. But I think that is overkill.

I tried sails new and put a web.config file in the root folder and tried to publish it with Web Matrix. And the website crashed. I still don't recall when things just run without crashing on the first shot with me.

I could see the streaming log (console.log in the Node.js case) with azure site log tail <sitename> and found out that it wasn't getting node modules. That's weird as I was pushing npm_modules too.

Then I tried with a GitHub repository. And that thing just worked. Without any issue, and also directly in production mode. (I seriously don't know how it switched to production mode. For production mode, I need to pass the parameter --prod with app.js)

Note: Don't forget to change server.js to app.js in web.config. I guess it's kind of required. I'm also skipping npm_modules with .gitignore.

Right now the first page is running without any issue. So now it's time to sail on Azure websites with SailsJS.

Here is the demo and my GitHub repo. Feel free to clone and give a PR with some demo application. I seriously like to see how far it can go.

Let me know if any further details are required.

Frequently Asked Questions

Can you deploy SailsJS applications to Azure Web Sites?

Yes, SailsJS applications can be deployed to Azure Web Sites. The most reliable method is using GitHub integration for continuous deployment. Simply connect your GitHub repository to Azure, and it will automatically deploy your application without requiring manual processes or VM setup.

What's the best way to deploy SailsJS to Azure without using a virtual machine?

Use Azure's GitHub integration for continuous deployment instead of spinning up a VM. Connect your SailsJS GitHub repository directly to Azure Web Sites, and the platform will handle the deployment automatically. Make sure to rename server.js to app.js in your web.config file and exclude npm_modules from your repository using .gitignore.

Why didn't my SailsJS deployment work when I manually uploaded files with Web Matrix?

Manual uploads with Web Matrix can fail because Azure may not properly install npm dependencies. GitHub integration is more reliable because it triggers Azure's build process, which automatically installs dependencies. Using GitHub also eliminates missing node_modules issues that can cause crashes.

How do I check if my SailsJS application is running correctly on Azure?

Use the Azure CLI command `azure site log tail <sitename>` to view streaming logs and console output from your Node.js application. This helps you diagnose issues like missing dependencies or configuration problems in real-time.

Do I need to manually set production mode for SailsJS on Azure?

No, SailsJS applications deployed via GitHub to Azure Web Sites automatically run in production mode without requiring the --prod parameter. This happens seamlessly when Azure processes your deployment, so you don't need to manually configure it.

Share this article