I just completed the learnyounode ‘http-uppercaser’ challenge. I couldn’t figure out why the .toUpperCase() method wasn’t capitalizing the chunk being returned. I still don’t understand what the difference is between the code I wrote and the ‘solution’ code. Can someone explain this difference and what’s happening under the hood?
My initial code that failed:
var fs = require('fs');
var http = require('http');
var port = process.argv[2];
// npm package that you can use to
// tranform stream data as it's passed through.
var map = require('through2-map');
var server = http.createServer(function(request, response) {
request.pipe(map(function(chunk) {
return chunk.toString().toUpperCase();
}));
request.pipe(response);
});
server.listen(port);
The ‘correct’ solution:
var fs = require('fs');
var http = require('http');
var port = process.argv[2];
// npm package that you can use to
// tranform stream data as it's passed through.
var map = require('through2-map');
var server = http.createServer(function(request, response) {
request.pipe(map(function(chunk) {
return chunk.toString().toUpperCase();
})).pipe(response);
});
server.listen(port);
Thanks!