Node.js 如何从nodeJs中的内部函数(SuperAgent)返回 “严格使用”; const express=require('express'); 常量app=express(); var请求=要求(“超级代理”); 风险值列表的形式=[ { “id_prof”:0, “身份证”:2 }, { “id_教授”:1, “身份证”:4 }, { “id_教授”:3, “id_ue”:0 }, { “id_教授”:4, “身份证”:1 }, { “id_教授”:2, “身份证”:3 } ]; app.get('/service/:name_prof',(req,callback)=>{ 请求(`http://localhost:5020/service/${req.params.name_prof}`,函数(err,res){ var result\u prof\u id=res.body.text; console.log(result\u prof\u id); var结果_ue _id; 对于(变量i=0;i
这将显示一个错误,说明:回调不是函数。。。。 我的问题很简单,怎样才能返回“某个结果”?? 我尝试过:返回“一些结果”Node.js 如何从nodeJs中的内部函数(SuperAgent)返回 “严格使用”; const express=require('express'); 常量app=express(); var请求=要求(“超级代理”); 风险值列表的形式=[ { “id_prof”:0, “身份证”:2 }, { “id_教授”:1, “身份证”:4 }, { “id_教授”:3, “id_ue”:0 }, { “id_教授”:4, “身份证”:1 }, { “id_教授”:2, “身份证”:3 } ]; app.get('/service/:name_prof',(req,callback)=>{ 请求(`http://localhost:5020/service/${req.params.name_prof}`,函数(err,res){ var result\u prof\u id=res.body.text; console.log(result\u prof\u id); var结果_ue _id; 对于(变量i=0;i,node.js,Node.js,这将显示一个错误,说明:回调不是函数。。。。 我的问题很简单,怎样才能返回“某个结果”?? 我尝试过:返回“一些结果” 任何建议都会被说服 app.get中中间件函数的第二个参数不是回调,而是响应对象。回调是第三个参数: 'use strict'; const express = require('express'); const app = express(); var request = require('superage
任何建议都会被说服 app.get中中间件函数的第二个参数不是回调,而是响应对象。回调是第三个参数:
'use strict';
const express = require('express');
const app = express();
var request = require('superagent');
var list_profs_ues = [
{
"id_prof": 0,
"id_ue": 2
},
{
"id_prof": 1,
"id_ue": 4
},
{
"id_prof": 3,
"id_ue": 0
},
{
"id_prof": 4,
"id_ue": 1
},
{
"id_prof": 2,
"id_ue": 3
}
];
app.get('/service/:name_prof', (req, callback) => {
request.get(`http://localhost:5020/service/${req.params.name_prof}`, function(err, res){
var result_prof_id = res.body.text;
console.log(result_prof_id);
var result_ue_id;
for (var i = 0; i < list_profs_ues.length; i++){
if (list_profs_ues[i]["id_prof"] == result_prof_id){
console.log(list_profs_ues[i]["id_ue"]);
result_ue_id = list_profs_ues[i]["id_ue"];
}}
request.get(`http://localhost:5030/service/${result_ue_id}`, function(err, res){
if(err || res.body.text == ""){
return callback("some result");
}else{
return callback("some result");
}
});
});
});
module.exports = app;
const server = app.listen(process.env.PORT || 5040, () => {
console.log('Express server listening on port %d in %s mode',
server.address().port, app.settings.env);
});
好的,但是next()是否可以返回一个值,而不是执行代码的第三部分!!请@Jorge,我如何从另一方
请求.get(
{name\u prof},function(err,res,cb){console.log(“该结果”);}
不是来自res.body
您想要什么?如果是,请将其保存到变量中。我不确定您想要什么,但它似乎与应用程序没有任何关系。get
回调用于调用下一个中间件函数。
app.get('/service/:name_prof', (req, res, next) => { ...