由于未发现配置错误而重新启动WSL计算机时,我的应用程序崩溃,但是我有未捕获的异常和未处理的拒绝侦听器

问题描述

由于/nodejs/rest-api/config目录中没有配置,因此每次重新启动WSL [ubuntu]计算机时,我的应用程序都崩溃了,我正在使用Config程序包在config/custom-environment-variables.json中配置环境变量,并且具有日志记录功能启动时对unhandled rejectionsuncaughtExceptions都有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 (将#修改为@)