Reputation: 11
I'm a beginner in nodeJs, I have created node server and write simple program, Sending the response I am using "response.end('some text')" working fine, but instead of using 'end' if I am trying to send response using 'send', then its throwing error "response.send is not a function."
Upvotes: 1
Views: 11062
Reputation: 203574
You have probably created an HTTP server based on the http
module.
response
, which is a http.ServerResponse
instance, does not have a .send
method. It does, as you found out, have a .end
method, though.
My guess is that you have seen some Express code. Express is a framework to build HTTP servers, and it provides additional functionality on top of the regular http
module.
One of those additional functions is a .send
method for HTTP response instances:
var express = require('express');
var app = express();
var server = app.listen(3000);
app.get('/', function(request, response) {
response.send('hello world!');
});
Upvotes: 4