Saturday 18 March 2017

node.js ~ express req.on()

This is an Express middleware thing.

I can't understand how to trigger the req.on() in the following. I've read numerous documents and forum question-answers.

Please explain to me what causes the req.on('data', f()) callback to fire?

I'm seeing the first console.log() but not the inner/second one.

From app.js:

app.use('/api/order', function (req, res, next) {
    console.log("req on(data)");
    req.rawBody = '';
    req.on('data', function (chunk) {
        req.rawBody += chunk;
        console.log("chunk", chunk);
    });

    next();
});



via user2367083

No comments:

Post a Comment