learnyounode icon indicating copy to clipboard operation
learnyounode copied to clipboard

UPPERCASERER - Why use through2-map

Open cesarZubillaga opened this issue 11 years ago • 1 comments

Hi! Instead of using this module i found the solution with this code:

var http = require('http');
var port = process.argv[2];
var server = http.createServer(function(req, res){
    if(req.method === 'POST'){  
        res.writeHead(200, {'Content-type' : 'text/html'});
        req.on('data', function(chunk){
            res.write(chunk.toString().toUpperCase());
        });
    }else{
        res.writeHead(200, {'Content-type' : 'text/html'});
        res.write('<form action="http://localhost:'+port+'"  method="post"><input type="text" name="text" value="text" /><input type="submit" name="enviar"/></form>');
        res.end();
    }
    req.on('end', function(){
        res.end();
    });
});
server.listen(port);

I know there are a few more lines of code, but apart from that: There is any other differences? Why should we use through2-map? Benefits or aplication in the real world?

Thanks a lot!

cesarZubillaga avatar Mar 24 '15 19:03 cesarZubillaga

@cesarZubillaga I guess through2-map illustrates how you can use streams and .pipe().

ralphtheninja avatar Mar 24 '15 20:03 ralphtheninja