“ beforeExit”是流程模块中流程类的事件,当Node.js清空其事件循环且没有其他工作要安排时会发出该事件。
用法:
Event:'beforeExit'
参数:此事件不接受任何参数作为参数。
返回值:此事件只返回回调函数以进行进一步的操作。
范例1:
index.js
// Node.js program to demonstrate the
// Process 'beforeExit' Event
// Importing process module
const process = require('process');
// Event 'beforeExit'
process.on('beforeExit', (code) => {
console.log('Process beforeExit event with code:', code);
});
// Event 'exit'
process.on('exit', (code) => {
console.log('Process exit event with code:', code);
});
// Display the first message
console.log('This message is displayed first.');
使用以下命令运行index.js文件:
node index.js
输出:
This message is displayed first. Process beforeExit event with code: 0 Process exit event with code: 0
范例2:
index.js
// Node.js program to demonstrate the
// Process 'beforeExit' Event
// Importing process module
const process = require('process');
// Updating the exit code
process.exitCode = 100;
// Event 'beforeExit'
process.on('beforeExit', (code) => {
console.log('Process beforeExit event with code:', code);
});
// Display the first message
console.log('This message is displayed first.');
使用以下命令运行index.js文件:
node index.js
输出:
This message is displayed first. Process beforeExit event with code: 100
参考: https://nodejs.org/dist/latest-v16.x/docs/api/process.html#process_event_beforeexit
相关用法
- Node.js process.nextTick()用法及代码示例
- jQuery UI dialog create(event, ui)用法及代码示例
- jQuery UI dialog close(event, ui)用法及代码示例
- jQuery UI dialog resizeStart(event, ui)用法及代码示例
- jQuery UI dialog dragStop(event, ui)用法及代码示例
- jQuery UI dialog dragStart(event, ui)用法及代码示例
- jQuery UI dialog resize(event,ui)用法及代码示例
- jQuery UI dialog open(event,ui)用法及代码示例
- jQuery UI dialog focus(event,ui)用法及代码示例
- Node.js Process exit用法及代码示例
- Node.js Process message用法及代码示例
- Node.js Process warning用法及代码示例
- Node.js Process uncaughtException用法及代码示例
- Node.js Process multipleResolves用法及代码示例
注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 Node.js Process beforeExit Event。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。