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/ to view the available versions.  Then click the "Downloads" link for the preferred version.
 
 
 
Then click "win-x64/".
 
 
 
And finally "node.exe" to download the executable.
 
 
 
After saving the file, upload 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 in /App_Data, the syntax would be:
 
nodeProcessCommandLine: "E:\web\username\htdocs\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);
 
Or download iisnode.zip for a sample iisnode.yml and test script.  Edit iisnode.yml and replace "username" with the username used for logging into the DiscountASP Control Panel, then upload iisnode.yml (and the test script) to the document root.
 
 
 
Then viewing the test file through a browser should show the new node.js version.