I'm running Debian 6 with NodeJS6 and request-promise.
I'm using request-promise to deliver web hooks. Currently, we are delivering around 2+M web hooks each day.
Most of the time everything runs fine, but there are cases where the HTTP request simply isn't delivered.
This is my simple code:
requestPromise({ url: 'https://change-iot-request/do', auth: { user: "switch", pass: "my-password" }, method: "GET", timeout: 15000, rejectUnauthorized: false})
.catch(function(err) {
console.log(err);
});
Sometimes the endpoint simply doesn't receive anything.
I've tried to run tshark to see if packages came through - nothing on any of the servers.
If I when it occurs run curl command with the same parameters the request DOES come through.
And if I restart the NodeJS it starts to deliver correctly again.
This is the error output:
{"name":"RequestError","message":"Error: ETIMEDOUT","cause":{"code":"ETIMEDOUT","connect":true},"error":{"code":"ETIMEDOUT","connect":true}
What to do?
Especially when curl does work so the connection should be fine.
it can be a lot of causes, maybe it's not node fold at all
ETIMEDOUT means that your server do not get response for request
you can try set a timeout, something like
var rp = require('request-promise');
var reqPromise = rp({
method: 'get',
uri: 'http://localhost:8080/test-connection-length',
timeout: 600000, // 10 min.
resolveWithFullResponse: true
});
or install node-retry and your server will re-run automatically when it's needed
Related
I have tor installed on my macOS 10.13.6
I want to use it for my axios xhr requests as a proxy but after a lot of searching I'm unable to find any useful resource. I've not configured tor as a proxy for my browsers and I'm not sure if is working after I run it from terminal. Is there any way to use it as I need and to check if works well?
I'm trying with this code but not sure if tor is really used
#!/usr/bin/env node
const axios = require('axios');
const socks = require('socks-proxy-agent');
const httpsAgent = new socks(`socks5://127.0.0.1:9050`);
axios({
method: 'GET',
baseURL: 'https://foo.bar',
url: 'baz/faz',
httpsAgent: httpsAgent,
});
I have been trying to call a web service running in Docker on my machine on port 4801. I can access the service in the browser, via curl and via .NET's HttpClient, but if I try from node.js (either using axios or the native http module) the request fails with status code 501 Not Implemented.
I eventually tracked the problem down to the fact that there is another process, called ServiceLayer.exe (description: "Logitech VC ServiceLayer"), listening on port 4801. How is Docker able to expose my service on that port such that it can be accessed by the methods listed above, but not from node?
Here is a minimal repro:
const axios = require("axios");
axios.get("http://localhost:4801")
.then(response => console.log(response.data))
.catch(error => console.log({
status: error.response.status,
headers: error.response.headers
}));
docker run -p 4801:8000 -d crccheck/hello-world
node test.js
Output:
{
status: 501,
headers: { server: 'websocket-sharp/1.0', connection: 'close' }
}
I am guessing the websocket-sharp bit is potentially significant.
I have already created backend using node js for sigin & signup page. Now I want to connect to node js . But i have no idea how to do that. I want to connect both react native with my node js. Can you help me ?
simply as how we do for web apps.
here is an example of error reporting
export default async function (body) {
console.log(JSON.stringify(body))
const res = await fetch(`${host}/api/report`, {
method: 'POST',
body: JSON.stringify(body),
headers: {
'Content-Type': 'application/json',
},
})
const { message } = await res.json()
if (message) return Toast({ message: message });
else return Toast({ message: 'network error' });
}
I have used fetch to send a POST request to my nodejs server
use API tool like postman or other and make your your nodejs APIs works fine and then connect to your React Native app as above.
You can use ngrok to connect Node with react-native. Run this command:
npm i ngrok -g # installing it globally
Then open another terminal. Run:
ngrok http 3000 # the port you are running on node
Then it will show an alternative link that you can use to test with your Node.
Note: if ngrok http 3000 doesn't work, try ngrok http -region us 3000.
The available ones are us, eu, ap, and au. In my case eu worked for me.
Then copy the link generated e.g. http://8074-129-205-124-100.eu.ngrok.io and test your backend if it displays APIs.
If the link works then you can use it with fetch. Uploading json data to send to MongoDB as the case maybe.
I'm using Parse for some quick MVP app development to prove some concepts. Everything is working fine and I'm simply trying to extend the abilities of our app by setting up some 3rd party integrations etc.
I would like to access my Cloud Code functions via the RESTful api, as documented here
I've changed the server address, but have no luck connecting and pulling the data.
I am using Node.js to connect to the REST api, which is being hosted on Heroku.
var options = {
host: 'https://###############.herokuapp.com',
port: 443,
path: '/parse/functions/'+req.param('text'),
method: 'POST',
headers: {
'X-Parse-Application-Id': '##############',
'X-Parse-REST-API-Key': '###########'
}
};
https.get(options, function(resp){
resp.on('data', function(chunk){
//do something with chunk
res.send(chunk)
});
}).on("error", function(e){
console.log("Got error: " + e.message);
res.send(e)
});
So far no luck. Any suggestions?
Hard to tell what exactly is wrong without seeing the Parse Server configuration, the Cloud Code function, and more importantly the server's response, but here's what worked for me:
curl -X POST -H "X-Parse-Application-Id: XYZUASDASDA" -H
"X-Parse-REST-API-Key: XYZUASDASDA" -H "Content-Type:
application/json" -d '{}'
http://localhost:3000/parse/functions/averageStars
Result: {"result":"Hello"}
Here's my test Cloud Code function:
Parse.Cloud.define('averageStars', function(request, response) {
response.success('Hello'); });
As a quick test, I suggest:
Try using CURL
Try the test function above
I've been pounding my head against the wall for days on this so I am turning to the smart folks at Stackoverflow to help. Here's the deal:
System Details
Node Version (can't be changed due to Electron dependencies): v4.1.1
Electron Version: v0.34.3
OS Version: Mac OSX Yosemite 10.10.5 (14F1021)
Issue Description
I'm building an Electron app that has to communicate with my company's application server. The server connection has to go over HTTPS. I'm using Node's built-in https module. When making a request to the server I'm getting the following error:
{ [Error: write EPROTO]
code: 'EPROTO',
errno: 'EPROTO',
syscall: 'write',
address: undefined }
I've done a ton of Googling on this and most everything I've found points to proxies but I'm not using a proxy. I've tried the following:
Setting rejectUnauthorized: false in the options hash
Modifying the secureProtocol option (no results)
Attempting to set the --tls-cipher-list (no idea what I'm doing there)
I can make the request over curl without issue. Unfortunately, I can't post the actual URL I'm making requests to.
Sample Code
Here's some sample code (Coffeescript) that illustrates the issue:
https = require 'https'
options = {
host: '[Application URL]'
path: '/'
method: 'GET'
port: 443
}
options.agent = new https.Agent(options)
callback = (response) ->
str = ''
console.log response
console.log "STATUS: #{response.statusCode}"
console.log "HEADERS: #{JSON.stringify(response.headers)}"
response.setEncoding 'utf-8'
response.on 'data', (chunk) -> str += chunk
response.on 'end', -> console.log str
makeRequest = ->
req = https.request options, callback
req.on 'error', (err) ->
console.log err
req.end()
makeRequest()
Does anyone have any idea what could be causing this issue? Is it a Node issue or something with the configuration of the application server? This bug is killing me and preventing me from hitting a milestone at work so any help would be greatly appreciated. Thanks!
To resolve this issue you are required to set https-proxy, which can be done with the following command:
npm config set https-proxy http://proxy.example.com:8080