ECONNREFUSED when trying to use jsreport - node.js

The following code:
var output = '<p>Hello</p>';
require("jsreport").render({
template: {
content: output
}
}).then(function(out) {
out.result.pipe(res);
});
});
returns this error :
Error: { [Error: Error during rendering report: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }
I believe it's because it cannot connect to internal jsreport server, but don't know why. Any idea on how to debug it or why it happens ?

We changed the embedded jsreport to stand alone jsreport . So we use the remote client to connect to this stand-alone instance. Now it works ! I don't know why.

Related

node-fetch even though server is online it keeps saying errconrefused

Connecting to the server through browser is possible and i get http code 200, I have directly copied the url from the browser to the node fetch:
await fetch(`http://localhost:9000/renderAvatar.3d?pant=http://localhost/assets/2.png&face=http://localhost/assets/0.png&shirt=http://localhost/assets/1.png&name=de&trick=e`)
The other server on the 9000 port is written in c# and has code like this:
HttpListener httpServer;
public void SomeFunction() {
//Some boilerplate for http server definitely not stolen amogus
httpServer = new HttpListener();
httpServer.Prefixes.Add("http://localhost:9000/");
httpServer.Start();
Task demo = Server();
demo.GetAwaiter().GetResult();
}
public async Task server() {
while(true) {
HttpListenerContext ctx = await httpServer.GetContextAsync();
HttpListenerRequest req = ctx.Request;
HttpListenerResponse resp = ctx.Response;
if(req.HttpMethod == "GET") {
if(req.Url.AbsolutePath.ToString() == "/renderAvatar.3d") {
var parameters = HttpUtility.ParseQueryString(req.Url.Query);
if(parameters.Count > 3) {
var pant = parameters[0].ToString();
var face = parameters[1].ToString();
var shirt = parameters[2].ToString();
var name = parameters[3].ToString();
// can't share more code due this is propertiary code
any access from the browser works but why node fetch doesn't work, i have very bad solution to this issue using chrome to open up avatar renderer then close the chrome programatically but this uses way too much memory and quite unncesary.
(This is on linux btw, port 9000 shouldn't be protected by firewall and this is a local server)
thrown error:
FetchError: request to http://127.0.0.1:9000/renderAvatar.3d?pant=http://localhost/assets/2.png&face=http://localhost/assets/0.png&shirt=http://localhost/assets/1.png&name=de&trick=e failed, reason: connect ECONNREFUSED 127.0.0.1:9000
at ClientRequest.<anonymous> (file:///home/
(confidental)/backend/node_modules/node-fetch/src/index.js:108:11)
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) {
type: 'system',
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
erroredSysCall: 'connect'
}
Turns out changing localhost to 127.0.0.1 on the c# app solves the issue, on linux localhost is automatically converted to 127.0.0.1 but c# app doesn't do that for some odd reason.
httpServer.Prefixes.Add("http://localhost:9000/");
to
httpServer.Prefixes.Add("http://127.0.0.1:9000/");

Error when attempting to PUT file to URL with Node request

I am trying to PUT a file to an S3 pre-signed URL. Doing so with bash/cURL works fine but with Node I am getting the following error:
Error: write EPIPE
at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:94:16) {
errno: -32,
code: 'EPIPE',
syscall: 'write'
}
Here is the code
const fs = require('fs');
const request = require('request');
stream = fs.createReadStream('/tmp/file');
r = request.put('https://s3.eu-west-2.amazonaws.com/bucketname/path?X-Amz-Content-Sha256=....&...');
stream.pipe(r).on('error', function(err) {
console.log(err);
});
EPIPE means that the writing request failed because the other end closed the connection. Looks like there might be some additional settings required inorder to work with amazon s3. I know that curl has native support for multipart/form-data. You can use this library to create readable multipart/form-data streams.
https://nicedoc.io/form-data/form-data
Or you can use third party libraries to send data
https://www.npmjs.com/package/s3-upload-stream
https://www.npmjs.com/package/streaming-s3

Mongoose can't connect: Error: querySrv ENOTIMP mongodb.tcp.cluster1-owfxv.mongodb.net

Mongoose can't connect to mogodb Atlas. It every times give me this error:
Error: querySrv ENOTIMP _mongodb._tcp.cluster1-owfxv.mongodb.net
I am running inside kubernetes cluster inside minikube locally.
If I run project directly then it works perfectly but with minikube it alwasy give me error.
Following is my code:
const url = "mongodb+srv://name:password#cluster1-owfxv.mongodb.net/test?retryWrites=true";
const mongoDbOptions = {
useNewUrlParser: true,
reconnectTries: 10,
autoReconnect: true
};
mongoose.connect(url, mongoDbOptions).then((r) => { }).catch((e) => {
console.log(e);
});
Error message is not so clear to me. Its strange that it works directly but with kubernetes cluster it does not work.
I will really appreciate for any contribution.
Try using connection string compatible with mongo driver 2.2.12 or later i.e. one with mongodb://username:password#host1:port,host2:port,host3:port/databaseName
It's not clear why connection to mongodb is not working with new url.
Using older url, as stated by #cEeNikC, even works when mongoose is giving the following error-
Error: querySrv ETIMEOUT _mongodb._tcp.cluster0.aq9un.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (dns.js:203:19) {
errno: 'ETIMEOUT',
code: 'ETIMEOUT',
syscall: 'querySrv',
hostname: '_mongodb._tcp.cluster0.aq9un.mongodb.net'
}
go to your cluster setting and enable access from all IP addresses (if you doing this for a learning purpose because it's not safe) .
I add this "&w=majority" and worked:
Before: mongodb+srv://:#sdq25.lepde.mongodb.net/myFirstDatabase?retryWrites=true
After: mongodb+srv://:#sdq25.lepde.mongodb.net/myFirstDatabase?retryWrites=true&w=majority

intern 2 configuration for BrowserStack behind a proxy

I'm unsure what the configuration should be running intern 2 tests against BrowserStack when running behind a proxy/firewall and currently seeing errors/timeouts.
My Current configuration is:
proxyPort : 9000,
proxyUrl : 'http://localhost:9000',
tunnel : 'BrowserStackLocal',
tunnelOptions : {
username : 'myusername',
accessKey : 'myaccesskey',
hostname : '<myproxyip>',
proxy : 'http://<myproxyip>:<myproxyport>'
}
I don't think I need hostname however if I remove that I immediately see the error getaddrinfo ENOTFOUND.
If use the above configuration it seems to get further, waits for a while then see:
Listening on 0.0.0.0:9000
Starting tunnel...
BrowserStackLocal v3.3
Connecting to BrowserStack using WebSocket protocol...
Connected.
Ready
Error: [POST http://(redacted)#<myproxyip>:4444/wd/hub/session] connect ETIMEDOUT
Error: connect ETIMEDOUT
at errnoException <net.js:904:11>
at Object.afterConnect [as oncomplete] <net.js:895:19>
FATAL ERROR
Error: [POST http://(redacted)#<myproxyip>:4444/wd/hub/session] connect ETIMEDOUT
Error: connect ETIMEDOUT
at errnoException <net.js:904:11>
The [POST http://(redacted)#<myproxyip>:4444/wd/hub/session] url doesn't seem right. Obviously I have this misconfigured & would appreciate any advice. I do struggle to understand intern's documentation when running behind a proxy.
It looks like you are behind some kind of proxy.
When you are behind proxy server, in order to use Intern with BrowserStack, you need to do two things:
Get Local Testing connection to work with your proxy, which you are doing, and you can see success message.
You have to make sure the node process that runs the Intern test works with your proxy. To enable proxy in a node application, the easiest option is to use global-tunnel npm package. There is a step-by-step guide available here.
Would love to answer any queries you might have! Do drop in a mail at support#browserstack.com
Umang,
BrowserStack Support.
I'm not sure but I think there is a bug in browserStack.js. Some proxy support is missing there I think. When I use configuration browserstack_conf.js as shown below tests run okay but there is an error message when Browserstack tries to publish the test results back to www.browserstack.com
[09:43:06] E/launcher - connect ETIMEDOUT 54.152.200.70:443
[09:43:06] E/launcher - Error: connect ETIMEDOUT 54.152.200.70:443
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
[09:43:06] E/launcher - Process exited with error code 199
I can fix this error with following steps:
npm install -g http-proxy-agent
Edit browserStack.js (located for example in C:\Users\myuser\AppData\Romaing\npm\node_modules\protractor\built\driverProviders\ add a require for this and initialize a agent and add to request.
For example add require top of browserStack.js
var HttpProxyAgent = require('http-proxy-agent');
And change the section with options to
let options = {
hostname: 'www.browserstack.com',
port: 443,
path: '/automate/sessions/' + session.getId() + '.json',
method: 'GET',
headers: headers//,
agent: new HttpProxyAgent('http://myproxy:3128')
};
I start Protractor with configuration below
// browserstack.conf.js
var browserstack = require('browserstack-local');
exports.config = {
specs: ['spec.js'],
webDriverProxy: 'http://myproxy:3128',
browserstackUser: 'myuser',
browserstackKey: '*****',
capabilities: {
project: 'BrowserStack (beyond Proxy)',
browserName: 'Chrome',
browser_version: '50.0',
os: 'OS X',
os_version: 'Yosemite',
'browserstack.local': true,
'browserstack.debug': true
},
// Code to start browserstack local before start of test
beforeLaunch: function(){
console.log("Connecting local");
return new Promise(function(resolve, reject){
exports.bs_local = new browserstack.Local();
exports.bs_local.start({'key': '*****',
'proxyHost': 'myproxy', 'proxyPort': '3128',
'binarypath': 'C:\\Users\\myuser\\Downloads\\BrowserStackLocal-win32\\BrowserStackLocal.exe'},
function(error) {
if (error) return reject(error);
console.log('Connected. Now testing...');
resolve();
});
});
},
// Code to stop browserstack local after end of test
afterLaunch: function(){
return new Promise(function(resolve, reject){
exports.bs_local.stop(resolve);
});
}
};

nodejs emailjs connect econnrefused, smtp

my node server starts fine, is running fine until i'm trying to send an email with emailjs...
this exception is thrown:
error : code 5
error : previous { [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }
error : smtp undefined
my code:
var ES = require('./email-settings');
var EM = {};
module.exports = EM;
EM.server = require("emailjs/email").server.connect({
host : ES.host,
user : ES.user,
password : ES.password,
ssl : true,
port : 465
});
EM.dispatchResetPasswordLink = function(account, callback)
{
EM.server.send({
from : ES.sender,
to : account.email,
subject : 'Password Reset',
text : 'something went wrong... :(',
attachment : EM.composeEmail(account)
}, callback );
}
in email-settings i define host, user, password... they are not undefined. my smtp-server is gmail. do i have to define any other settings? maybe for my gmail-account? is emailjs using port 80 or so? my app is running on 8003
im looking for a solution for quite a long time now... thx for help :)
You need to unlock captcha code in gmail. As below link
https://accounts.google.com/b/0/displayunlockcaptcha

Resources