What is modern way to hosting `node.js` applications on Windows 10 and Windows Server 2012 and newer?
Asked Answered
A

1

10

I want to know how to deploy my node.js application (it uses Koa) on Windows 10, Windows server 2012 and newer.

In Internet I see old tips for using iisnode, but at the same time I see that people worry that developers no answer for many important questions (related with iisnode) and long time doesn't make changes to the iisnode code sources. :(

What is modern way to hosting node.js applications on Windows 10 and Windows Server 2012 and newer?

I would be grateful for link to step-by-step article.

Advertent answered 5/8, 2019 at 5:19 Comment(3)
To clarify, are you asking how to run a NodeJS-based web-server on Windows for production workloads? As opposed to running it for local development?Clothesbasket
The cop-out answer is that the vast majority of production NodeJS deployments are on Linux or a BSD variant and they don't run on Windows - this explains why there isn't much documentation available.Clothesbasket
@Dai, I want to know how can I deploy my node.js application on windows server (for production) and on windows 10 (as service, without console window opened, if it is possible).Advertent
C
16

There are a few ways you can run NodeJS on Windows for production workloads.

It's important to first understand that Windows has built-in (kernel mode!) support for HTTP servers called HTTP.sys which IIS and other web-servers use to serve HTTP traffic rather than simply opening a listening socket on port 80 (this is how Microsoft's IIS beat the pants off Apache in the web-server benchmarks back in the late 1990s).

Your options are:

  • Expose NodeJS directly to port 80/443

    • This is the simplest approach though with many drawbacks. But provided you don't need to run different multiple applications and non-NodeJS code on the server then this is a valid option. Just remember to disable HTTP.sys first.
  • Run NodeJS behind HTTP.sys

    • The author of the iisnode library also wrote another lib called httpsys for NodeJS (as running behind IIS uses many of the same techniques as running behind HTTP.sys): https://github.com/tjanczuk/httpsys - unfortunately it's out of date, but there really isn't much code to it so you can probably hack it yourself to work with the latest versions of Node. This is one of the points of open-source! ("Don't complain, fix it!")
  • Run NodeJS behind IIS with Microsoft's fork of iisnode:

    • While the original iisnode is abandoned, Microsoft actually took over ownership and forked it to https://github.com/Azure/iisnode which does seem to be actively maintained - and Microsoft has a vested interest in maintaining it because Microsoft wants to make money from the world running its apps on Azure regardless of whatever language, platform or OS they're using.
      • ...though it seems MS isn't releasing binaries (not since 2017), so you'll have to build it yourself (for details, see my footnote).
  • Run NodeJS behind an nginx port for Windows

  • One last option (and probably the best for your situation) is to run NodeJS on Windows as-is and use IIS' Application Request Routing (ARR) feature:


Regarding Azure's fork of iisnode:

As it's 2024 now, and because the azure/iisnode fork hasn't made any releases since 2017, I felt I should do a quick-check to see how, exactly, Azure employs iisnode; for example, to see if they have a private build.

...and I found Azure is runnning a private build 2.27.0 of their fork of IISNode which was built in January 2018, while the last public release was 2.26 in Feb 2017.

...but if you want 2.27 to download for yourself, I've exfiltrated the binaries from Azure and posted them to a related Issue in their repo.

Interestingly, there have been a bunch of commits made since 2.27 was built, so most people are better-off making their own build of iisnode rather than using the exfiltrated binaries above.

Clothesbasket answered 5/8, 2019 at 5:43 Comment(5)
This is an excellent breakdown of the modern options for running NodeJS in production on Windows. Most stuff I've found it outdated or not for Windows. Thank you!Monaco
Also wondering if PM2 fits into this list somewhere. blog.cloudboost.io/nodejs-pm2-startup-on-windows-db0906328d75Monaco
Woops, nevermind that last comment about PM2, I see that the last instructions link you posted actually uses PM2. Perfect!Monaco
Azure/IISNode - latest release dates are 2017, so I would retract that "actively" maintained, as this doesn't apply any longer :)Statutable
@Statutable Azure seems to be using a private build from 2018 which I've added a link to download - but it seems to work just fine with Windows 11 + Windows Server 2022. But I recommend building from the repo as even Microsoft's private build is missing some updates.Clothesbasket

© 2022 - 2024 — McMap. All rights reserved.