TypeError:res.sendFile不是一个函数 [英] TypeError: res.sendFile is not a function

查看:71
本文介绍了TypeError:res.sendFile不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在完成一个基本的MEAN教程,并且已经遇到了麻烦.收到"TypeError:res.sendFile不是函数"错误

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

推荐答案

请重新安排回调参数:

function(req,res){}

示例:

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

这篇关于TypeError:res.sendFile不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆