I'm trying console log the json for an API after sending my request through a proxy, however when the code runs the console logs nothing. Here is my code.
const express = require('express');
const app = express();
const fetch = require('node-fetch')
app.listen(3000, () => console.log('listening at 3000'));
app.use(express.static('public'));
app.use(express.json())
app.post('/api', (request, response) => {
let steamIdValue = request.body.steamId
let steamInventoryApiLink = 'https://steamcommunity.com/profiles/' + steamIdValue + '/inventory/json/730/2'
require('request-promise')({
url: 'xxxxx',
proxy: 'xxxxx'
}).then(function(data){
const request = require('request');
request({
'url': steamInventoryApiLink,
'method': "GET",
'proxy':'http://' + data + ':80'
},function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
})
}, function(err){ console.error(err); });
});
Is there a fix, or a better way to go about doing this?
BELOW IS A LOG WITH THE SUGGESTED CHANGES
(using 'request-promise' in both requests and logging the error, and the ip address.)
Aleeshas-MacBook-Pro:LoopTradesRound2 aleeshamoseley$ node index.js
listening at 3000
193.8.1.88
RequestError: Error: tunneling socket could not be established, cause=connect ECONNREFUSED 193.8.1.88:80
at new RequestError (/Users/aleeshamoseley/Desktop/LoopTradesRound2/node_modules/request-promise-core/lib/errors.js:14:15)
at Request.plumbing.callback (/Users/aleeshamoseley/Desktop/LoopTradesRound2/node_modules/request-promise-core/lib/plumbing.js:87:29)
at Request.RP$callback [as _callback] (/Users/aleeshamoseley/Desktop/LoopTradesRound2/node_modules/request-promise-core/lib/plumbing.js:46:31)
at self.callback (/Users/aleeshamoseley/Desktop/LoopTradesRound2/node_modules/request/request.js:185:22)
at Request.emit (node:events:527:28)
at Request.onRequestError (/Users/aleeshamoseley/Desktop/LoopTradesRound2/node_modules/request/request.js:877:8)
at ClientRequest.emit (node:events:527:28)
at ClientRequest.onError (/Users/aleeshamoseley/Desktop/LoopTradesRound2/node_modules/tunnel-agent/index.js:179:21)
at Object.onceWrapper (node:events:642:26)
... 5 lines matching cause stack trace ...
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
cause: Error: tunneling socket could not be established, cause=connect ECONNREFUSED 193.8.1.88:80
at ClientRequest.onError (/Users/aleeshamoseley/Desktop/LoopTradesRound2/node_modules/tunnel-agent/index.js:177:17)
at Object.onceWrapper (node:events:642:26)
at ClientRequest.emit (node:events:527:28)
at Socket.socketErrorListener (node:_http_client:454:9)
at Socket.emit (node:events:527:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'ECONNRESET'
},
error: Error: tunneling socket could not be established, cause=connect ECONNREFUSED 193.8.1.88:80
at ClientRequest.onError (/Users/aleeshamoseley/Desktop/LoopTradesRound2/node_modules/tunnel-agent/index.js:177:17)
at Object.onceWrapper (node:events:642:26)
at ClientRequest.emit (node:events:527:28)
at Socket.socketErrorListener (node:_http_client:454:9)
at Socket.emit (node:events:527:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'ECONNRESET'
},
options: {
url: 'https://steamcommunity.com/profiles/76561198034202275/inventory/json/730/2',
method: 'GET',
proxy: 'http://193.8.1.88:80',
callback: [Function: RP$callback],
transform: undefined,
simple: true,
resolveWithFullResponse: false,
transform2xxOnly: false
},
response: undefined
}
console.logstatement do you expect to do anything? Also, running this code will do nothing but to open a http server on port 3000 (which should log listening at 3000), are you actually sending a request to the/apiroute? Please show us how you are sending that request, and notice that your server never responds to that request. - Bergirequestandrequest-promisein the same code? - Bergi