K
K
kiloper2013-11-06 12:44:55
Angular
kiloper, 2013-11-06 12:44:55

Asynchronous node.js request processing (express)?

Dear experts, please help with the following problem. There is a simple code on node.js (express)

01	var poster = function (req, out)
02	{
03	 var body = '';
04	 console.log(1);
05	 
06	 req.on('readable', function(){
07	  console(2);
08	  body += req.read();
09	 }).
10	 on('end', function(){});
11	  console(3);
12	  out.end('end');
13	}
14	 
15	app.post('/publish', poster);

When executing a POST request, 1 is written to the console, that is, it does not enter the readable and end events.
I make a request through AngularJS:
$http.post('/publish', JSON.stringify({user: 23, mesg: "Message"})).success(function(answer){
            alert(answer);
        });

Tell me, please, how to make sure that all the same events are executed as needed, I need to process the request asynchronously. Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2013-11-06
@kiloper

and what kind of event is this, readable? I thought that you need to subscribe to data and read the request body in pieces (in fact, this is what you get).

K
kiloper, 2013-11-06
@kiloper

data doesn't work either.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question