iisnode icon indicating copy to clipboard operation
iisnode copied to clipboard

Can't get Express working

Open pateras opened this issue 11 years ago • 9 comments

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.

pateras avatar Dec 06 '13 17:12 pateras

place web.config in the same folder as app.js

rramachand21-zz avatar Dec 08 '13 00:12 rramachand21-zz

It is in the same folder, as my post says.

pateras avatar Dec 08 '13 00:12 pateras

if possible can you paste your app.js ?

rramachand21-zz avatar Dec 08 '13 00:12 rramachand21-zz

specifically, the app.get portion.

rramachand21-zz avatar Dec 08 '13 00:12 rramachand21-zz

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 }); });

pateras avatar Dec 08 '13 01:12 pateras

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

rramachand21-zz avatar Dec 08 '13 01:12 rramachand21-zz

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 avatar Dec 08 '13 01:12 pateras

@pateras did you get this issues resolved.I am facing exactly same.

umashankarsharma avatar Mar 22 '18 15:03 umashankarsharma

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

bothaj avatar Jul 05 '18 18:07 bothaj