const http = require('http');
const fs = require('fs');
http.createServer(function (req, res) {
(async () => {
const file = fs.createWriteStream('log.txt');
let logger = new console.Console(file, file);
logger.log('http://www.good1230.com');
logger.log('http://good1230.com/tag/1/');
logger.log('http://good1230.com/tag/2/');
fs.writeFile('log2.log', '', function (err) {
if (err) {
console.log(err);
}
});
let options = {
flags: 'a',
encoding: 'utf8',
}
let stderr = fs.createWriteStream('log2.log', options);
let logger2 = new console.Console(stderr);
logger2.log('http://www.good1230.com');
logger2.log('http://good1230.com/tag/1/');
logger2.log('http://good1230.com/tag/2/');
logger2.log('http://good1230.com/tag/3/');
logger2.log('http://good1230.com/tag/4/');
logger2.log('http://good1230.com/tag/5/');
logger2.log('http://good1230.com/tag/6/');
setTimeout(() => {
fs.writeFile('log2.log', '', function (err) {
if (err) {
console.log(err);
}
});
}, 1000 * 3600 * 24);
})();
res.writeHead(200, { 'Content-Type': 'text/html' });
res.write('Node.js says hello!');
res.end();
}).listen(8080);