Tag: needle.js

针:node.js在POST上返回500

我有我自己的restAPI,在内部调用一个NLP API,为此我必须在他们的URL上发布一些数据。 我正在使用针来达到这个目的,但是有一些我无法理解的错误,而我自己的api正在返回500到前端。 这是我的server.js代码的一部分: app.post('/api/get',function(req,res) { //console.log(req); console.log("here in post "); if(!req.body){ return res.send(400); } //console.log(req.body.msg); var searchQuery = req.body.msg; var options = { 'api-key' : '3080a0e0-1111-11e5-a409-7159d0ac8188' }; needle.post('http://api.cortical.io:80/rest/text/keywords?retina_name=en_associative',searchQuery,options,function(err, resp){ if(err){ console.log('something went wrong :' + err); } console.log('Got :'+resp ); }); 每次我都会here in post ,但之后就没有了。 我也很好奇,这是正确的方式来指定我的外部API的API键。 谢谢。

如何使用MailChimp API发送电子邮件

我在nodejs中创build一个应用程序来使用MailChimp发送一封电子邮件。 我试图使用https://apidocs.mailchimp.com/sts/1.0/sendemail.func.php,但将其改为使用3.0 API,因为1.0似乎不再工作(大惊喜)。 我已经安装了我的应用程序 var apiKey = '<<apiKey>>', toEmail = '<<emailAddress>>', toNames = '<<myName>>', message = { 'html': 'Yo, this is the <b>html</b> portion', 'text': 'Yo, this is the *text* portion', 'subject': 'This is the subject', 'from_name': 'Me!', 'from_email': '', 'to_email': toEmail, 'to_name': toNames }, tags = ['HelloWorld'], params = { 'apikey': apiKey, 'message': message, […]

处理成功的HTTP承诺,如果一个蓝鸟失败

我对Promises相当陌生,一直试图让这段代码正常工作。 这是我的。 var Promise = require('bluebird'); Promise.join(getProducts, getPricing, function(products, pricing) { console.log('products: ' + products.body); console.log('pricing: ' + pricing.body); // Add pricing to products here res.send(products.body); }) .catch(function(e) { console.log(e); res.sendStatus(500); }); 要求… 我想同时调用这两个API,并在两个完成时处理结果。 如果定价API失败,我仍然希望返回没有定价的产品。 如果产品API失败,我想错误发送500回到客户端。 我的代码似乎工作,如果两个API调用都成功,但总是进入捕获,如果失败,并忽略任何成功的调用。 如果我使用同步Promise链,我可以很好地工作,但是我想同时调用这两个API。 我怎样才能asynchronous调用这两个API并在catch之外处理结果?

请求大量链接时,节点中的请求行为不一致?

我目前正在使用这段代码连接到一个庞大的链接列表(共2458个链接,在https://pastebin.com/2wC8hwad倾倒),以从众多来源获取提要,并将它们交付给我的用户程序。 它基本上将一个大规模的数组分成多个批次(数组),然后派生一个进程来处理一个批处理,以请求每个存储的链接获得一个200状态码。 只有当一个批次完成时,才会发送下一个批次进行处理,当完成分叉处理时将被断开连接。 然而,我正面临着这个逻辑如何performance出不一致的问题,尤其是它请求代码的部分。 const req = require('./request.js') const process = require('child_process') const linkList = require('./links.json') let processor console.log(`Total length: ${linkList.length}`) // 2458 links const batchLength = 400 const batchList = [] // Contains batches (arrays) of links let currentBatch = [] for (var i in linkList) { if (currentBatch.length < batchLength) currentBatch.push(linkList[i]) else { […]