Reputation: 4570
I have the following code in server.js
(where app is an express instance), that is supposed to return a file index.html
which is located in the same directory as server.js
.
app.get('/', function (req, res) {
var indexPath = path.resolve('index.html');
res.sendFile(indexPath);
});
I log out indexPath
and it is the correct path to my html file. Yet I get the following error
TypeError: res.sendFile is not a function
and call trace:
at Object.handle (/Users/alexanderbollbach/Desktop/ABApp/server.js:54:9) at next_layer (/Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/route.js:103:13) at Route.dispatch (/Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/route.js:107:5) at /Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/index.js:195:24 at Function.proto.process_params (/Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/index.js:251:12) at next (/Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/index.js:189:19) at Layer.jsonParser [as handle] (/Users/alexanderbollbach/Desktop/ABApp/node_modules/body-parser/index.js:31:38) at trim_prefix (/Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/index.js:226:17) at /Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/index.js:198:9 at Function.proto.process_params (/Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/index.js:251:12)
Upvotes: 0
Views: 1481
Reputation: 521
In older versions of Express, the method used to be senfile
, not sendFile
.
Update to Express 4.14, you will be able to use sendFile
. 4.14 is also a security update, so it is highly recommended.
You can add this in your package.json
file: "express": "^4.14.0"
.
Upvotes: 2