javascript - Node.js:console.err() 是同步还是异步?

标签 javascript node.js event-loop

我使用 AWS,并且希望使用 console.err() 将所有错误写入 stderrstderrAWS Cloud Watch 捕获并记录。我不想阻塞事件循环。

Node.js 实现中的 console.err() 是异步的吗?

最佳答案

这取决于操作系统以及 stderr 的“去向”。

来自the Node.js documentation :

process.stdout and process.stderr differ from other Node.js streams in important ways:

  1. They are used internally by console.log() and console.error(), respectively.

  2. Writes may be synchronous depending on what the stream is connected to and whether the system is Windows or POSIX:

    • Files: synchronous on Windows and POSIX
    • TTYs (Terminals): asynchronous on Windows, synchronous on POSIX
    • Pipes (and sockets): synchronous on Windows, asynchronous on POSIX

关于javascript - Node.js:console.err() 是同步还是异步?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60987847/

相关文章:

Eclipse 未处理的事件循环异常,不再处理 Windows 7

javascript - 单选按钮的 OnChange 事件处理程序(输入类型 ="radio")不能作为一个值工作

python - 如何取消asyncio的loop.call_later()?

javascript - HTML 设置选择时的默认文本

javascript - axios onUploadProgress 和 onDownloadProgress 不适用于 CORS

google-chrome - NodeJS 和 Socket.io : Chrome not loading with WebSockets

javascript - Node.js 中的反射

iphone - 什么是事件循环或运行循环?

javascript - 不要在后退导航中显示模态弹出窗口

javascript - 尽管使用目标 ="_blank",但 React Markdown 链接不会在新选项卡中打开