javascript - 我如何在 NodeJS 中的这个 async module.exports 中看到结果
问题描述
我的代码中有这个模块需要调试。它在一个文件中,我们可以调用GCP 云调度程序调用的test.js。
const run = require("../../run");
module.exports = async (req, res) => {
await run(false);
res.send("done");
};
我想记录 res 看看发生了什么。像这样的东西:
console.log('hello');
module.exports = async (req, res) => {
await run(false);
console.log(res)
res.send("done");
};
console.log('world');
但我没有得到那个console.log。我会得到
hello
world
解决方案
您将首先看到“Hello”“World”,因为它会在您将模块导入某个文件时打印。console.logs 在模块“全局范围”中!!
我没有完全给你代码,但我觉得你没有调用函数,只是导出!
尝试类似:
请求文件.js
const run = require('../../run');
module.exports = async (req, res) => {
const resp = await run(false);
console.log(resp)
res.send("done");
};
测试文件.js
const req = require('./requestfile');
async function main () {
await req();
}
main();
推荐阅读
- c# - 如何使用按钮设置启动/加载表单
- ios - react-native-elements 按钮背景颜色不起作用
- python - 在虚拟环境中找不到 contextlib
- java - Apache Camel whenExchangeReceived 和 whenAnyExchangeReceived - 访问 Exchange
- python - 从 PDF 转换为图像时无法读取图像数据
- visual-studio - 如何在 VisualStudio 2017 的 ASP.net 项目中使用 Bootstrap-Vue?
- c# - SQL 脚本的 C# Linq 等效项没有响应
- python - 在键入文本时使散景 TextInput 回调响应
- python - 全局 numpy 数组在函数内部发生更改,但没有对其进行全局引用
- pseudocode - 记录类型伪代码的问题,显示每行的最后一列