I'm new to node.js and just curious why res.end() erases my file
Let's say I have this code
index.js
var http = require('http');
var fs = require('fs');
http.createServer(function(req, res) {
var file_to = fs.createWriteStream('file_to.txt');
req.pipe(file_to);
req.on('end', function() {
res.end();
});
}).listen(8080);
file_from.txt contains "copy me"
file_to.txt is empty
In terminal I do node index.js
In second terminal tab I do curl --upload-file file_from.txt http://localhost:8080
file_to.txt remains empty
If remove
req.on('end', function() {
res.end();
});
file_to.txt will contain "copy me" as expected
Why?
Aucun commentaire:
Enregistrer un commentaire