javascript - TypeError : res. sendFile 不是函数

标签 javascript node.js express

我正在学习一个基本的 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');

最佳答案

请重新安排回调参数:

function(req,res){}

例子:

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

关于javascript - TypeError : res. sendFile 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35150431/

相关文章:

javascript - Observable.Interval 的 RxJS 多重订阅

javascript - 无法将属性 "max-content"添加到 @key-frames

java - 如何使用套接字与socketio交互

node.js - 我可以安装 node_modules 一次,并且需要所有时间吗

node.js - Sails.js 中的唯一属性失败

javascript - 如何使用 POST 方法传递参数? NodeJS

javascript - 找不到 Twitter 注册表单变量signup_ui_metrics 的 javascript 代码

javascript - 使用 ReactPDF 加载 React 时出现 PDF 错误

node.js - Node.js 和 Kakashi 中的日语音译

javascript - 加载模板失败