I went to study OC these days, but I haven't learned it yet. It's still a long time before changing careers, so let's review the knowledge of node.
There are many people coming and going in each language, but I can’t live without node. I didn't use it to develop it, but I just used relatively more js, so it's better to study nodes. Stream has a high status in nodes. I also come to see this content when I am free. I am still a novice on the road to node.
I downloaded the nodeschool course today and saw an example of it. (I modified a little bit)
var concat = require('concat-stream');var http = require('http');var qs = require('querystring'); var server = http.createServer(function (req, res) { if (req.method === 'POST') { req.pipe(concat(function (body) { body = qs.parse(body.toString()) res.end(Object.keys(body).join('/n')); })); } else res.end(); }); server.listen(5000);The meaning of this question is that if you ask you to invert the post data, I won’t do it. The principle is the same, but the requirements are different. We use the concat plugin to direct the data flow to concat when the form is submitted. This example is to take the data from the form post.
For testing, I use the request library.
var request = require('request')request.post(' http://127.0.0.1:5000 ', {form:{"name": "ryan","age" : 23}}, function(err,res,body){console.log('received successfully:')console.log(res['body']) // name age})Start the server and run the test, you can see that we have posted this object. The concat-stream module mainly makes buffer connections. My understanding is that when you transmit in the form of a buffer, you can transmit any type. In npmjs, it transmits an image. After we receive it, we get the data of this image, and we can use this to upload, copy, and the principles are the same.