Don
Don

Reputation: 526

TypeError: Object #<ServerResponse> has no method 'send'

I've been working on an Express app and I just started getting a super weird error saying TypeError: Object #<ServerResponse> has no method 'send'. It started as I was trying to set up some routing for my app via the router provided by Express. I did some Googling and found that other people that were getting the TypeError: Object #<ServerResponse> has no method __ (fill in the blank) were either not using Express, or they were doing something weird with the router. So, I created a new app file named app-test.js and trimmed out all of the extraneous code, including the router. However, I'm still getting the same error. Here's my setup now while I'm trying to figure out the problem:

server.js

var app = require("./app-test");

app.set("port", process.env.PORT || 8000);

var server = app.listen(app.get("port"), function () {

var host = server.address().address;
var port = server.address().port;

console.log("Example app listening at http://%s:%s", host, port)
});

module.exports.app = app;
module.exports.server = server;

app-test.js

var express = require('express'),
app = express(),
path = require('path');

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.get('/testing', function(req, res) {
    res.send('Hello World!');
});

module.exports = app;

I know that Express builds on Node.js's http's ServerResponse object. So, certain methods like .end() will still work even if Express isn't setup. However, the really weird thing about this problem is that Express's .render() method still works fine.

I'm completely stumped by this one. Any help would be greatly appreciated.

Upvotes: 2

Views: 989

Answers (1)

Don
Don

Reputation: 526

To fix this I ended up just reinstalling Express via npm install and it fixed the issue. I'm guessing that I hit a file during a refactor and didn't realize it.

Upvotes: 1

Related Questions