chat-example
chat-example copied to clipboard
Filepath error using sendFile instead of sendfile
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');
Another way:
var path = require('path');
app.get('/', function (req, res) {
res.sendFile(path.resolve('index.html'));
});
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.
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