I am using PayPal-node-SDK module in my Node JS application to create a payout.
My code is
var paypal = require('paypal-rest-sdk');
paypalRequest = { sender_batch_id: 'h4mq5b3xr',
email_subject: 'You have a payment' },
items:
[ { recipient_type: 'EMAIL',
amount: { value: 100, currency: 'USD' },
receiver: //sandbox text account,
note: 'Thank you.' } ]
}
return paypal.payout.create(paypalRequest, true, function (paypalErr, paypalResponse) {
console.log('paypalErr',paypalErr);
console.log('paypalResponse',paypalResponse);
}
But when i call the function i am getting the error
paypalErr { [Error: read ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }
paypalResponse undefined
can anyone suggest what is the error and how can i rectify it?
Please help.
I found the solution. When run the corresponding function , i was using the local url (eg: 192.122.2.2) . That why it was showing the error. But when i tried to run the same on live (eg www.example.net) the function is working properly.
It worked for me. I am not sure it is the correct answer. But it solved my problem.
Related
Struggling to get this one to work now;
const superagent = require("snekfetch");
const Discord = require('discord.js')
module.exports = {
name: "cat",
category: "fun",
description: "Sends a random image of a cat",
usage: "[command]",
run: async (client, message, args, level) => {
//command
superagent.get('https://nekos.life/api/v2/img/meow')
.end((err, response) => {
const lewdembed = new Discord.MessageEmbed()
.setTitle("Random cat")
.setImage(response.body.url)
.setColor(`#00FF00`)
.setFooter(`owo`)
.setURL(response.body.url);
message.channel.send(lewdembed);
})
}
};
Throwing up this error;
TypeError: Cannot read property 'body' of null
at /home/runner/Manias-Bot/commands/fun/cat.js:16:22
at /home/runner/Manias-Bot/node_modules/snekfetch/src/index.js:212:22
I can see the error is with (response.body.url), but unsure how to solve this. Any help?
Firstly, snekfetch has been deprecated, you should use node-fetch instead.
See https://www.npmjs.com/package/snekfetch
Secondly, the error is because response is null - almost certainly because you have an error when trying to get that resource. My guess would be ECONNREFUSED but you can confirm this by checking the value of err and response in your get, i.e.
superagent.get('https://nekos.life/api/v2/img/meow')
.end((err, response) => {
console.log(err, response)
})
This give me...
[Error: connect ECONNREFUSED 0.0.0.0:443] {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '0.0.0.0',
port: 443
} null
So as you can see - the server is refusing the request and the response is null
To fix this you should use a package that isn't deprecated and make sure you are trying to fetch a resource that you have permission/access to get.
When fetching anything - it is always a good idea to check to see if there are any errors before trying to do something with the expected result.
I am trying to use aws encryption sdk in a NestJS application, the next code source shows the implementation.
import { Controller, Get } from '#nestjs/common';
import {KmsKeyringNode, encrypt} from '#aws-crypto/client-node'
#Controller('encryption')
export class EncryptionController {
// constructor() {}
#Get()
async crypt() {
const generatorKeyId = "generatior key";
const masterKeyId = "master key id";
const keyring = new KmsKeyringNode({keyIds:[masterKeyId], generatorKeyId: generatorKeyId});
const plainText = "My passwords for senstive data";
const context = {
accountId: "100",
purpose: "youtube demo",
country: "Sri Lanka"
};
const { result } = await encrypt(keyring, plainText, { encryptionContext: context });
console.log(result)
}
}
but when I execute a request to see the result of my implementation I receive the next error
Error: connect EHOSTUNREACH 169.254.169.254:80
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1128:14) {
message: 'Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1',
errno: 'EHOSTUNREACH',
code: 'CredentialsError',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2020-06-09T11:41:47.638Z,
originalError: {
message: 'Could not load credentials from any providers',
errno: 'EHOSTUNREACH',
code: 'CredentialsError',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2020-06-09T11:41:47.638Z,
originalError: {
message: 'EC2 Metadata roleName request returned error',
errno: 'EHOSTUNREACH',
code: 'EHOSTUNREACH',
syscall: 'connect',
address: '169.254.169.254',
port: 80,
time: 2020-06-09T11:41:47.637Z,
originalError: [Object]
}
}
}
However I copy a nodejs script from this tutorial to see if it works with my aws sdk set up
and I did not receive any error, also if a execute aws kms encryption methods in the cli I hadn't any error.
I tried to export AWS_SDK_LOAD_CONFIG=1 variable how I saw in other similar errors.
Does anyone know what's going on?
I had the same problem. It cost me quite some head ache because I had this running in AWS Fargate and debugging is not that easy there.
The error means the Javascript SDK can not find the AWS credentials.
Here you can see in what order the SDK tries to load the credentials from:
https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html
My error was quite embarrassing, I just had a typo in my environment variables. My variable was AWS_ACCESSS_KEY_ID instead of AWS_ACCESS_KEY_ID. (Quite hard to see the difference, right?)
So probably double check the names of your environment variables (or config files)
I am new to Node.js. I want to work with internationalization. I am trying using i18next. I have written this code:
i18n.init({
lng: 'en',
debug: true,
load: ['en', 'ar'],
fallbackLng: 'en',
backend: {
"loadPath": path.join(__dirname,"locale/en/translation.json")
},
getAsync:false
}, (err, t) => {
console.log("this is key value :"+(t("key")));
return t;
});
And in my en/translation.json file I have this contents:
{
key:"hello anil"
}
When I run the program I get this error: i18next::translator: missingKey en translation key key
What went wrong? Please help me out.
Check your debug log.
I found the loadPath is not what I thought, after fixing the path it works.
The reason is my js file is in build directory, so the path becomes build/locales/en.json not /locales/en.json.
the error message,
[Error: ENOENT, open '/opt/www/build/locales/en.json']
errno: 34,
code: 'ENOENT',
path: '/opt/www/build/locales/en.json' } ]
this is my fixed config,
backend: {
loadPath: 'locales/' + '{{lng}}.json',
},
Disclaimer: This is related to another question I asked here. I was advised to ask a new question rather than to update that one, I hope that this is correct. If not please let me know and ignor this question.
I have been trying to use a Neo4j in Microsoft Azure, using this tutorial. I created a VM running Linux and neo4j. I know his works fine because I have been able to access the database via the web admin portal, where I can create and delete entries. However the problem comes when I try to use node.js to insert elements.
Here is the code for the script:
function insert(item, user, request) {
//comment to trigger .js creation
var neo4j = require('neo4j');
var db = new neo4j.GraphDatabase('http://<username>:<password>#neo4jmobile.cloudapp.net:7474');
var node = db.createNode({ name: item.name });
node.save(function (err, node) {
if (err) {
console.error('Error saving new node to database:', err);
}
else {
console.log('Node saved to database with id:', node.id);
}
});
request.execute();
}
I am getting this error message:
Error saving new node to database: { [Error: connect ETIMEDOUT]
stack: [Getter/Setter],
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
__frame:
{ name: 'GraphDatabase_prototype__getRoot__1',
line: 76,
file: '\\\\10.211.156.195\\volume-0-default\\bf02c8bd8f7589d46ba1\\4906fa4587734dd087df8e641513f602\\site\\wwwroot\\App_Data\\config\\scripts\\node_modules\\neo4j\\lib\\GraphDatabase.js',
prev:
{ name: 'GraphDatabase_prototype_getServices__2',
line: 99,
file: '\\\\10.211.156.195\\volume-0-default\\bf02c8bd8f7589d46ba1\\4906fa4587734dd087df8e641513f602\\site\\wwwroot\\App_Data\\config\\scripts\\node_modules\\neo4j\\lib\\GraphDatabase.js',
prev: [Object],
active: false,
offset: 5,
col: 12 },
active: false,
offset: 5,
col: 12 },
rawStack: [Getter] }
Any help would be appreciated!
Your URL is still wrong: http://<username>:<password>#http://neo4jmobile.cloudapp.net:7474 should be http://<username>:<password>#neo4jmobile.cloudapp.net:7474
In the referenced tutorial (which is quite good btw) he says:
var db = new neo4j.GraphDatabase('http://<username>:<password>#<your neo url>.cloudapp.net:7474');
Where refers to the hostname, i.e.: neo4jmobile
I have the same code for my Windows and Linux. It works on Windows but failed with my Linux.
Code:
request({url:target_url}, // ANY URL WILL FAIL
function (err, response, body) {
console.log(err);
Out put error for this in my console:
{ [Error: connect EAGAIN] code: 'EAGAIN', errno: 'EAGAIN', syscall: 'connect' }
I guess this is not an issue with the request module but i don't know where to get help. Thanks for any kind of tips!