0

I am constantly getting:

express deprecated res.sendfile: Use res.sendFile instead 

here is my code:

app.get('/*', function (req, res) {

  var myUrl = req.url.split('/')[1];

  myownfunction(myUrl, function (err, rows) {

    if (rows.length != 0) {
      res.sendfile('views/article.html');
    }
    else
    {
      res.sendfile('views/404.html');
    }
  });
});

I changed the sendfile to uppercase sendFile, but it breaks. what should i do?

update

when I run my code:

app.get('/upload', function(req, res){
  res.sendFile('views/upload_file.html');
});

I get this error: TypeError: path must be absolute or specify root to res.sendFile

KARTHIKEYAN.A
  • 18,210
  • 6
  • 124
  • 133
passion
  • 1,000
  • 6
  • 20
  • 47
  • "it breaks", how does it break? What errors are you getting? – Ben Fortune Apr 20 '17 at 07:42
  • @BenFortune i updated the question with the error i get: TypeError: path must be absolute or specify root to res.sendFile – passion Apr 20 '17 at 07:50
  • 1
    did you tried `res.sendFile(path.join(__dirname,"views/upload_file.html"))` (you'll probably need to import nodeJs's path module) – mJehanno Apr 20 '17 at 07:54

1 Answers1

1

Use path.join() function to configure file path.

app.get('/upload', function(req, res){
  res.sendFile(path.join(__dirname,"views/upload_file.html"))
});
KARTHIKEYAN.A
  • 18,210
  • 6
  • 124
  • 133