chat-example icon indicating copy to clipboard operation
chat-example copied to clipboard

Filepath error using sendFile instead of sendfile

Open AndrewSouthpaw opened this issue 10 years ago • 3 comments

The tutorial is inconsistent about using res.sendfile or res.sendFile. If res.sendFile is used (since sendfile is deprecated), using

res.sendFile('index.html');

doesn't work, throwing an error about the path not being specified properly. Here's what I did to fix it:

res.sendFile(__dirname + '/index.html');

AndrewSouthpaw avatar Sep 13 '14 22:09 AndrewSouthpaw

Another way:

var path = require('path');

app.get('/', function (req, res) {
    res.sendFile(path.resolve('index.html'));
});

evertonbaima avatar Sep 24 '14 11:09 evertonbaima

For some reason I'm getting error TypeError: Object #<ServerResponse> has no method 'sendFile' at Object.handle when I try either of the above methods.

MikeiLL avatar Sep 30 '14 02:09 MikeiLL

Ah. Had an older of express installed (maybe based on the package.json file from repository. Express docs Note: res.sendFile requires Express version to be at least 4.8.0

MikeiLL avatar Sep 30 '14 02:09 MikeiLL