On IIS, node.js is handled by the iisnode module.  To run a node.js script, a handler mapping will first have to be added to the site's web.config to process the .js script, or all .js scripts, using the iisnode module.  To run a custom node.js version, see the Custom node.js Version section.
 
 
Handler Mapping
 
To have all .js scripts handled by the iisnode module, add module "iisnode" to the handlers element of the web.config as in the syntax example below:
 
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="iisnode" path="*.js" verb="*" modules="iisnode" />
    </handlers>
  </system.webServer>
</configuration>
 
If there are other files using the .js extension in the application, necessitating targeting specific files, update the handler path.  For example, if the below ztest.js file were in the document root, the syntax would be:
 
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="ztest" path="ztest.js" verb="*" modules="iisnode" />
    </handlers>
  </system.webServer>
</configuration>
 
Note when adding a handler for more than one file, each will require a unique name.
 
 
Testing node.js
 
To test node.js, the syntax below may be copied, making sure to use the file extension .js.  Or download and extract ztest.js; then upload the file to the site and visit the page in a browser.
 
  var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello world');
}).listen(process.env.PORT);
 

Custom node.js Version
 
Visit https://nodejs.org/en/download/releases/ and click the version number link under "Node.js" for the package download.
 


Then under "Binary Downloads" select the win x64 zip.


After downloading the zip, extract node.exe.
 
Then upload the extracted node.exe to an /App_Data directory on the site.



iisnode.yml
 
Create a new text file and name it "iisnode.yml".  In that file add the following line:

nodeProcessCommandLine: "server path to file"
 
For the example above where node.exe was placed into /App_Data the syntax would be:

nodeProcessCommandLine: "E:\web\FTPusername\app_data\node.exe"

To test the update, create a separate .js file and add the following syntax to display the version of node.js the site is using:

var http = require('http');
http.createServer(function(req,res) {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.end('Node.js ' + process.version);
}).listen(process.env.PORT);

To test the update, create a separate .js file and add the following syntax to display the version of node.js the site is using:

Or download node.zip for a sample iisnode.yml and test script.  Edit iisnode.yml and replace "FTPusername" with the FTP username for the site, then upload iisnode.yml (and the test script) to the document root.


And view the ztest.js in a browser to show the version.