Alvaro Alvaro - 3 months ago 32
Node.js Question

iisnode won't run Express

I'm trying to run express using iisnode. I followed the examples provided but when trying to use the latest Express version with a basic example, there's no way to make it work.

I'm getting the error

Cannot GET /node/parislight/hello.js
and other times, just a
The webpage cannot be found
.

My created a
hello.js
file (main express file) taken from the express docs.

var express = require('express')
var app = express()

app.get('/', function (req, res) {
res.send('Hello World!')
})

var server = app.listen(process.env.PORT, function () {

var host = server.address().address
var port = server.address().port

console.log('Example app listening at http://%s:%s', host, port)

})


I added the necessary
web.config
file (extracted from the express example within iisnode)

<configuration>
<system.webServer>

<!-- indicates that the hello.js file is a node.js application
to be handled by the iisnode module -->

<handlers>
<add name="iisnode" path="hello.js" verb="*" modules="iisnode" />
</handlers>

<!-- use URL rewriting to redirect the entire branch of the URL namespace
to hello.js node.js application; for example, the following URLs will
all be handled by hello.js:

http://localhost/node/express/myapp/foo
http://localhost/node/express/myapp/bar

-->

<rewrite>
<rules>
<rule name="myapp">
<match url="myapp/*" />
<action type="Rewrite" url="hello.js" />
</rule>
</rules>
</rewrite>

</system.webServer>
</configuration>


I gave all the necessary permissions to the used App Pool in IIS.

Answer

It needs to use the full path:

The path specified in app.get calls must be the full path of the request.

Source

Looking like this now:

app.get('/node/parislight/myapp/demo', function (req, res) {
  res.send('Hello World!')
})

Acceding to it through:

http://localhost/node/parislight/myapp/demo

Comments