0
當我將此作爲服務器運行時,goto localhost:8080'已保存!'在控制檯中打印兩次。並且'Honey Bee'在mynewfile1.txt中追加了兩次爲什麼?在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);