0
aufgerufen Wenn ich dies als Server ausführen, und goto localhost: 8080 "Gespeichert!" wird zweimal in der Konsole gedruckt. Und auch 'Honey Bee' ist zweimal in meinernewfile1.txt angehängt. Warum ist das?Funktion wird zweimal in Nodejs
var http = require('http');
var fs = require('fs');
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.write('Hello World!');
fs.readFile('head.html', function (err, data) {
res.write(data);
res.end();
});
fs.appendFile('mynewfile1.txt', 'Honey Bee', function (err) {
if (err) throw err;
console.log('Saved!');
});
}).listen(8080);