javascript - 如何将 HTTP 请求映射或关联到 Node.js 中的数据库调用?

标签 javascript node.js http v8

我有一个带有 MySQL 数据库的 Node 应用程序。我想将每个 HTTP 请求关联或映射到 MySQL 数据库调用。 即要求是以某种方式将 HTTP 请求标识传递给随后的异步数据库调用(下一个异步调用完全在一个新的上下文中)。

请给我一些建议。

最佳答案

经过大量研究,我发现在 node.js 中,async_hooks 模块提供了一个 API 来注册回调,跟踪在 Node.js 应用程序中创建的异步资源的生命周期。

const async_hooks = require('async_hooks');
const eid = async_hooks.executionAsyncId(); // Return the ID of the current execution context.
const tid = async_hooks.triggerAsyncId(); // Return the ID of the handle responsible for triggering the callback of the current execution scope to call.

关于javascript - 如何将 HTTP 请求映射或关联到 Node.js 中的数据库调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56869687/

相关文章:

Javascript: console.log 到 html

node.js - Express 和 Redis - 如果该用户存在 session ,则不允许访问

c# - 如何使用 C# 连接到路由器 "panel"

http - 为什么 HTTP 请求称为 "get"和 "post"?

来自 ajax 的 javascript 没有得到正确的执行

javascript - ngCamera 不适用于 iOS

javascript - 如何创建一个简单的解决方案来绕过声音而不是自动播放?

javascript - node.js:删除 require.cache 不起作用

node.js - 如何从谷歌数据存储中祖先查询的返回对象中检索完整的键?

c# - 修改 Http Status Code 文本