3

Form my another question can't do multiple res.send in express.js

Can't find "res.write" in http://expressjs.com/4x/api.html

here is code example:

response.write("foo");
response.write("bar");
//...
response.end()
Community
  • 1
  • 1
emj365
  • 2,028
  • 2
  • 19
  • 24
  • 3
    Something about inheriting from the NodeJS response from the http module if I had to guess. You can read about it in the NodeJS http module docs. – Benjamin Gruenbaum Aug 29 '14 at 08:25
  • Here is the api reference http://nodejs.org/api/http.html#http_response_write_chunk_encoding – sbarow Aug 29 '14 at 08:51

1 Answers1

6

This is because res.write isn't part of express API. This is a server without express:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.write('Hi,');
  res.end('Hello World\n');
}).listen(1337, '127.O.O.1');

So you see the http module already has already that req and res arguments, and express make do with adding properties to these objects.

Vinz243
  • 9,654
  • 10
  • 42
  • 86