问题
I am working through a basic MEAN tutorial, and I am already hitting a wall. Getting 'TypeError: res.sendFile is not a function' error
//package.json
{
"name": "http-server",
"main": "server.js",
"dependencies": {
"express": "^4.13.4"
}
}
//server.js
var express = require('express');
var app = express();
var path = require('path');
app.get('/', function (res, req) {
res.sendFile(path.join(__dirname + '/index.html'));
});
app.listen(1337);
console.log('Visit me at http://localhost:1337');
回答1:
Please re-arrange callback arguments:
function(req,res){}
Example:
app.get('/',function(req, res){
res.sendFile(path.join(__dirname+'/index.html'));
});
回答2:
you have mistake here app.get('/', function (res, req) just write app.get('*', function(req, res) and it will work
来源:https://stackoverflow.com/questions/35150431/typeerror-res-sendfile-is-not-a-function