TypeError: res.sendFile is not a function

痴心易碎 提交于 2021-02-16 18:00:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!