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



我正在学习一个基本的 MEAN 教程,我已经碰壁了。收到"类型错误:res.sendFile 不是函数"错误

//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');

请重新排列回调参数:

function(req,res){}

例:

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

你在这里有错误app.get('/', function (res, req)只是写app.get('*', function(req, res)它会工作

最新更新