我对Node.js还比较新,不太确定完全理解这个错误的含义是什么:
我的意图是,如果我无法读取设置文件,则退出。这是按设计进行的。我知道其他方法可能更好,但我的问题是为什么会出现上述错误?我正在运行 Node.js 8.12.0,在 Windows 7 64 位上运行。
(原文)
我读到过,不应该导入process.on('uncaughtException', err => {
^
TypeError: process.on is not a function
process
,因为它会自动注入。我的代码是这样的:var settings;
var jsonfile = require("jsonfile");
var file = "server/settings.json";
try {
var obj = jsonfile.readFileSync(file);
settings = obj;
} catch (err) {
var msg = err + ". Exiting";
console.error(msg);
throw new Error("Fatal");
}
// some other functions
process.on('uncaughtException', function (err) {
console.error((new Date).toUTCString() + ' uncaughtException:', err.message)
console.error(err.stack)
process.exit(1)
})
module.exports.login = login;
module.exports.logout = logout;
我的意图是,如果我无法读取设置文件,则退出。这是按设计进行的。我知道其他方法可能更好,但我的问题是为什么会出现上述错误?我正在运行 Node.js 8.12.0,在 Windows 7 64 位上运行。