0

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?

fat
  • 5,098
  • 4
  • 28
  • 31

1 Answers1

1

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.

Pavan Kumar Sunkara
  • 3,025
  • 21
  • 30
  • Thanks mate, your solution works for the static file. I didnt try this on nodester because it failed on my local machine, but as you said, the node process is somewhere else in nodester... its so obvious. I'm going to check for the layout problem and report here – fat Jun 30 '12 at 12:41
  • I wasn't able to get the '/' running correctly, i edited my code, replacing with the folllowing line: res.render('index.jade',{layout:__dirname+'/views/layout.jade'}); Any ideas? – fat Jun 30 '12 at 13:18
  • Which express version are you using? If it's 3.0.0*, then layout doesn't work. You have to have a line `extends layout` in your `index.jade` to render the `layout.jade`. – Pavan Kumar Sunkara Jun 30 '12 at 13:35
  • Check this for example, http://stackoverflow.com/questions/11267135/partial-not-defined-in-jade – Pavan Kumar Sunkara Jun 30 '12 at 13:36
  • It's weird but i can't log into nodester's admin panel, anyway i uploaded the package.json from my local installation, which says "express": "2.5.8". I will wait until the admin panel is back online – fat Jun 30 '12 at 15:18
  • Hi, sorry for being late, but the problem was exactly an upgrade to 3.0.xbeta , thank you very much for your help! I'm also going to try nodejitsu btw ;) – fat Jul 01 '12 at 16:49