如何解决由于未发现配置错误而重新启动WSL计算机时,我的应用程序崩溃,但是我有未捕获的异常和未处理的拒绝侦听器
由于/nodejs/rest-api/config
目录中没有配置,因此每次重新启动WSL [ubuntu]计算机时,我的应用程序都崩溃了,我正在使用Config程序包在config/custom-environment-variables.json
中配置环境变量,并且具有日志记录功能启动时对unhandled rejections
和uncaughtExceptions
都有2个事件侦听器,并且该函数在我的主应用程序文件中被调用一次
这是我的应用主代码
const express = require('express');
const app = express();
const winston = require('winston');
require('./startup/logging')(); /// logging is here to handle errors from routes and dbs
require('./startup/routes')(app);
require('./startup/db')();
require('./startup/config')();
app.use(express.static('public'))
const port = process.env.PORT || 8080;
app.listen(port,()=>{
winston.info(`listening to port ${port}`);
});
这是我的日志记录功能
const winston = require('winston');
require('winston-mongodb');
const db_URI = 'mongodb://localhost:27017/MyUdemy';
require('express-async-errors');
module.exports = function () {
winston.exceptions.handle(
new winston.transports.File({filename:'uncaughtExceptions.log'})
);
process.on('unhandledRejection',(exc)=>{
throw exc;
});
/// to log errors in files
winston.add(new winston.transports.File({filename:'logfile.log'}));
/// to log errors in mongodb
winston.add(new winston.transports.MongoDB({db:db_URI}));
}
我想避免崩溃的应用程序,并知道是否有任何解决方案可以永久设置环境变量
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。