5

I need some advice for getting a basic express app to work on my site. The site is hosted on Arvixe.com windows hosting. I can run code on my localhost and it works but as soon as I move it to the Arvixe site it is giving me a 404 error - file or directory not found.

At the root of my site I have a folder called node_modules that has express in it. I also have a app.js file and a web.config file.

This is the web.config file:

<configuration>
  <system.webServer>
    <handlers>
            <add name="iisnode" path="app.js" verb="*" modules="iisnode" />
    </handlers>
    <defaultDocument enabled="true">
        <files>
            <add value="app.js" />
        </files>
    </defaultDocument>
  </system.webServer>
</configuration>

This is the app.js file:

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

app.get('/', function(request, response) {
    response.send("This would be some HTML");
});

app.get('/api', function(request, response) {
    response.send({name:"Raymond",age:40});
});
app.listen(process.env.PORT);

The only difference between the localhost version and this version is there is a web.config file and in app.js I changed app.listen to use PORT instead of a local port number. The only files I'm accessing should be app.js and express and they are both there.

I'm very new to node.js and express. Am I missing something about how these files communicate between one another or what is happening to stop my site from running? Is there a simple way I could debug things like this in the future?

2
  • Is this on their shared hosting or do you have a VPS? If shared, did you have to ask them to install it or was it already there? Commented Sep 22, 2014 at 21:47
  • The node site is on their shared windows hosting. I had to ask them to install node. I also had a Linux shared hosting and had to install it myself. The Linux version was a much harder process to work with for me, but I am a windows user so I guess that's expected. I ended up switching my sites all over to windows and it has been a good experience ever since. Commented Sep 26, 2014 at 21:17

1 Answer 1

3

I found a way to get this to work. I added this code to my web.config:

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

I'm surprised this was necessary because app.js was set to the default document. Apparently Express requires rewriting the urls instead of using the default document tags.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.