【问题标题】:File System in Node js causing errorNode js中的文件系统导致错误
【发布时间】:2016-03-13 07:27:57
【问题描述】:

fs.writeFile();上传图片时出现问题。顺便说一句,图像已上传,但发生了一些服务器问题。像 502 Bad Gateway 在腻子中,我可以看到类似“永远检测到的脚本被信号杀死:SIGKILL

之类的错误消息

短代码:

fs.writeFile(userUploadedImagePath, imageBuffer.data, function(err ) {

        json_response['success'] = true;
        res.json(json_response);

      });

【问题讨论】:

  • SIGKILL 听起来像是您的服务器正在杀死您的进程(可能是由于内存使用过多)。
  • json_response 对象中有什么?当 express 在函数中对对象进行字符串化时,它可能会导致问题。将其包装在 try catch 中并记录错误。

标签: node.js fs


【解决方案1】:

尝试记录错误信息:

fs.writeFile('helloworld.txt', 'Hello World!', function (err) {
   if (err) return console.log(err);
   ...
});

然后检查是什么问题

【讨论】:

  • 在这个 console.log("something); 中工作正常。但 res.json() 不工作。那是我的问题。
  • 那么当进程关闭时,您的服务器日志中没有打印错误信息?顺便说一句,你用永远打印错误 -o out.log -e err.log your-node.js
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-04-06
  • 1970-01-01
  • 2015-02-22
  • 1970-01-01
  • 2012-12-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多