Announcing node.js support
Today we're happy to announce beta support for node.js, and you can now run your node.js applications on AppHarbor. In this blogpost we'll walk you through the things you should be aware of when deploying node.js apps to AppHarbor and some background on why we're adding support for it.
As you probably know by now we're committed to giving the .NET world the fastest and most convenient way to deploy, manage and scale applications on Windows-based servers in the cloud. As such we didn't immediately think of node.js as the most obvious second platform to support. With recent developments in the node.js community, in particular Microsoft's support of a native Windows implementation along with the performance and stability it brings, node.js on Windows has become viable.
A number of fiery talks by Glenn Block on why node.js has a place in the Windows world further pushed us to make this decision. Finally Tomasz Janczuk made it incredibly easy for us to support it with the iisnode project, which allows us to run node.js inside IIS.
Without further ado let's dive into preparing and deploying a node.js application on AppHarbor. As this is a node.js blogpost we'll of course deploy a chat application and will use Ryan Dahl's node chat demo application. Applications that use iisnode needs a web.config in order to configure the application in IIS. When developing the application you can easily test it by installing iisnode and it's dependencies on your local system which are listed on the Github page. Make sure to take a look at the samples included to get a better understanding of how you can use the web.config file to configure your application.
Start by cloning the application from GitHub:
git clone https://github.com/ry/node_chat.git
The node chat uses the server.js file as the starting point, so we'll make sure to register that in our new web.config
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
<iisnode loggingEnabled="false" />
<rewrite>
<rules>
<rule name="myapp">
<match url="/*" />
<action type="Rewrite" url="server.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Most of this is taken from the express sample web.config which show the iisnode module is configured to handle the server.js file and alse how URL rewrites are configured so we don't have to use the filenames directly. Two things are worth noting:
- Disable logging: The iisnode elements sets
loggingEnabled="true"
which is necessary to run your node.js application on AppHarbor. The iisnode module writes a log file to the directory where the application runs and writing to the filesystem is not supported by default on AppHarbor. Alternatively, you can enable instance file system writes in the application settings on AppHarbor. - Environment variables: iisnode automatically configures the node.js application with environment variables read from appSettings. In the example above the `NODE_ENV` variable is set. This sets the current node environment and you could should add a configuration variable on AppHarbor with the value "production". That value will then be replaced when you deploy the application as [described here](http://support.appharbor.com/kb/getting-started/managing-environments). If you've provisioned [add-ons](https://appharbor.com/addons) to your application their configuration variables will also be automatically injected.
With this configuration we're good to go and the application can be deployed to AppHarbor:
git remote add appharbor https://appharbor.com/<foo>.git
git push appharbor master
That's it - AppHarbor will the detect the node.js application and deploy it to the the application server. Go to the application's URL (this example is deployed here if you want to take a look) and start chatting with all your friends.
A couple of final remarks:
- NPM: If you're using NPM you'll have to make sure that all dependencies are included in the repository. We may support automatic download of dependencies with NPM in the future, but are waiting until a stable Windows version is ready.
- Websockets are not currently supported
- Node.js support on AppHarbor should only be used for development and beta testing purposes. We wanted to give our users the opportunity to try node.js soon and iron out any kinks with us, but for now this feature should be considered early beta. Please don't put your "mission critical" node.js apps on AppHarbor just yet.