Friday, 21 April 2017

Node.js Express Middleware order

I'm very new to nodejs. I wrote my own middleware function to change incoming csv String to a JSON String.

The middleware stack looks like this:

app.use(bodyparser.text());
app.use(csvmiddleware);

app.use('/api',router);

The csvmiddleware function just changes the content of req.body and calls next(). the csvmiddleware function shows that req.body contains a JSON String. Then I call router.route('/r').put(putobj) and the putobj function outputs the CSV String. the putobj output also appears before the csvmiddleware output in the console. What is wrong with my order? I want the JSON String in my putobj function so I can save it to MongoDB. Thanks for help



via Jan V.

No comments:

Post a Comment