Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: res.sendFile is not a function

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');
like image 826
Taylor Huston Avatar asked Mar 14 '23 10:03

Taylor Huston


1 Answers

Please re-arrange callback arguments:

function(req,res){}

Example:

app.get('/',function(req, res){
  res.sendFile(path.join(__dirname+'/index.html'));
});
like image 182
Sunil Kumar Avatar answered Mar 23 '23 17:03

Sunil Kumar