类型错误:res.sendFile不是一个函数。

5

我正在学习基础的MEAN教程,但是遇到了问题。出现了“TypeError: res.sendFile is not a function”的错误。

//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
app.get ('/', function (req,res) { - Harpreet Singh
2个回答

9
请重新排列回调参数:
function(req,res){}

例子:

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

0

你这里有错误 app.get('/', function (res, req) 只需要写成 app.get('*', function(req, res) 就可以了


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接