Question

i just started using nodester as nodejs application paas and i stepped into a couple of problems.

Let me clarify that my local machine runs node 0.7 while on nodester i'm using node 0.6.17

The following code is inside my server.js file, executed by the platform:

app.get('/static', function(req,res) {
  res.sendfile('views/myFile.html',function(error){
    if(err)
      res.send('An error has occurred');
  });
});
app.get('/', function(req,res){
  res.render('index.jade');
});

The rest of the code is the code generated by Express.js in particular the configuration is

app.set('views', __dirname + '/views');
  app.use(express.static(__dirname + '/public'));
  app.set('view engine', 'jade');
  app.set('view options', {layout: 'layout.jade'}); //added by me but with no results

If i run this configuration in my local machine, everything works fine, the '/' route, perfectly sends the index.jade view inside the proper layout.jade view. The '/static' route, sends index.html without problems.

But if i run this code on nodester (after editing package.json and asking for node 0.6) i get different results:

  1. The '/' route doesn't render the layout.jade, but only index.jade. This is pretty weird, since i just edited the layout.jade file, generated by express!

  2. The '/static' route just throws an error, that i can catch with the callback. So the html file is not sent.

Where am i wrong? i am probably missing something.. any ideas?

Was it helpful?

Solution

Answer for 2

In nodester the node process might be running from a different directory making process.cwd() not equal to your app's root directory.

To solve this issue, use the following code

app.get('/static', function(req,res) {
  res.sendfile(__dirname + '/views/myFile.html',function(error){
    if(err)
      res.send('An error has occurred');
  });
});

Answer for 1

Similiar problem as above. So, please check and tell me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top