Iis – NodeJS scripts only work if run from Node.exe and not from iisnode

iisiis-7.5node.jswindows-server-2008-r2

Running NodeJS scripts from IIS using iisnode cause path and 404 issues, scripts try to search files in places they aren't while when running them from Node command line directly they work perfectly. (For example, re adding the root folder to the url while it's already present)

The website running for this have no specific configuration but using iisnode for server.js file and using server.js as index. There's no url rewrite or anything on IIS side, but in Node script side, some URL rewrite are used and i think the problem may be IIS altering the rewriting.

I tried to use config file from this iisnode issue as i had no specific configuration with no luck (Error 500 instead of path issues, cannot open rewriting rules tab from IIS manager until config file reverted)
https://github.com/tjanczuk/iisnode/issues/160#issuecomment-5606547

The server runs IIS 7.5, iisnode x64, NodeJS x64, the script use process.env.PORT || 8080 to get port to use ( process.env.PORT for when it's behind IIS, if empty use 8080, used for devs runnning node at front)

Tested every iisnode samples bundled, they are all working.

Best Answer

I faced the same problem that you are having and it's working but you have to do some modifications:

  1. IIS changes the URL format so use the following instead of the normal url and port :
http.createServer(function (req, res) {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('Hello, world! [helloworld sample]');
}`).listen(process.env.PORT);

`

  1. Add new web.config file in the js folder so that the IIS can realize that it should send your js file to the IISNode module instead of handling it as a normal js file

    enter image description here