课程代码
This commit is contained in:
33
nodejs/nodeExperiment7/index3.js
Normal file
33
nodejs/nodeExperiment7/index3.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
console.log('Start');
|
||||
|
||||
const filePath = path.join(__dirname, 'example.html');
|
||||
if (!fs.existsSync(filePath)) {
|
||||
fs.writeFileSync(filePath, '<html><body>Hello World</body></html>', 'utf8');
|
||||
}
|
||||
|
||||
fs.readFile(filePath, 'utf8', (err, data) => {
|
||||
console.log('File data read');
|
||||
|
||||
if (err) {
|
||||
console.log(__dirname);
|
||||
console.log(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
console.log('Timeout');
|
||||
}, 0);
|
||||
|
||||
setImmediate(() => {
|
||||
console.log('Immediate');
|
||||
});
|
||||
|
||||
process.nextTick(() => {
|
||||
console.log('Next Tick');
|
||||
});
|
||||
});
|
||||
|
||||
console.log('End');
|
||||
Reference in New Issue
Block a user