iisnode
iisnode copied to clipboard
Can't get Express working
I've set IISNode up on a server, and followed a guide to get a simple hello world node.js app running with it. It works fine and it's externally accessible via the internet. However, when I try to incorporate my existing express app, it's like node/express aren't even there.
This is my web.config file (had to replace the brackets to get it to show up):
[configuration][system.webServer][handlers][add name="iisnode" path="app.js" verb="*" modules="iisnode" /] [/handlers][/system.webServer] [/configuration]
That is at the IIS application's root directory, along with app.js which is my main express file. What's interesting is if I go to localhost/TestApp/app.js, I get back:
Cannot GET /TestApp/app.js
However, if I try a different file, like localhost/TestApp/public/htm/index.htm, I get back the file that is located there (in HTML, as expected). Also, if I try and do a server call (e.g. localhost/TestApp/GetUsernames).
What's even more interesting is that if I mess up the port (e.g. app.listen(process.env.PORT2 );), I get this when I try and access localhost/TestApp.js:
iisnode encountered an error when processing the request.
HRESULT: 0x2 HTTP status: 500 HTTP reason: Internal Server Error
If the port is correct (app.listen(process.env.PORT2);), I get Cannot GET /TestApp/app.js, so it does look like IISNode is executing app.js (how else would it be failing when I mess up the port), but nothing seems to be working.
How might I fix this, or at least diagnose the problems?
Thank you.
place web.config in the same folder as app.js
It is in the same folder, as my post says.
if possible can you paste your app.js ?
specifically, the app.get portion.
It's a standard express app. It works just fine locally and I've hosted it on numerous sites. They all look something like this:
app.get("/Something", function(request, response) { response.send({ Success: true }); });
http://localhost/TestApp/app.js would be served only if you have app.get("/TestApp/app.js", function(...) ...);
i.e there needs to be a URI match
Agreed, I was only trying that because that's what the test app did. I thought maybe IISNode might do something special when you try to fetch the server file. None of my routes work, though. http://localhost/TestApp/Something fails as well.
@pateras did you get this issues resolved.I am facing exactly same.
I get the same issue. been struggling for some time now and not sure how to fix it. Did you find a solution to your problem?
in my case this works app.get('/node/BAICEmalahleni/baic/foo', function (req, res) { res.send('Hello from foo! [express sample]'); });
but sendFile does not work app.get('/node/BAICEmalahleni/baic/index',function (req, res) { res.sendFile('/index.html'); });
get this error iisnode TypeError: res.sendFile is not a function
and now changed something and get this error Cannot GET /node/BAICEmalahleni/index
I installed URL Rewrite and IISNode
Any help would be much appreciated