【问题标题】:Read EIO error when closing database关闭数据库时读取 EIO 错误
【发布时间】:2017-02-16 19:06:03
【问题描述】:

我有一个使用 MongoDB 的 Express 应用程序。 我在开发时使用 Nodemon 重新启动我的进程。为了在我重新启动我的应用程序时关闭我的数据库连接,我调用:

db.close()

关于以下事件:

process.on('SIGINT', fn ...)

process.on('exit', fn ...)

但是,当我的应用重新启动时出现错误:

throw er; // Unhandled 'error' event
  ^

Error: read EIO
  at exports._errnoException (util.js:890:11)
  at TTY.onread (net.js:550:26)

如何防止这种情况发生?

【问题讨论】:

    标签: node.js mongodb express error-handling nodemon


    【解决方案1】:

    添加此事件(gulp 示例):

    gulp.task('serve', function () {
        nodemon({
            script: './server.js',
        })
        .once('exit', function () {
            console.log('Exiting this process');
            process.exit();
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-20
      相关资源
      最近更新 更多