how to connect to redis cluster using multiple node connection string? - redis-cluster

I am trying following code but not working. Getting error
[ioredis] Unhandled error event: ClusterAllFailedError: Failed to
refresh slots cache.
const Redis = require("ioredis");
const cluster = new Redis.Cluster([
{
port: 6379,
host: "172.x.x.x",
},
{
port: 6379,
host: "172.x.x.x",
},
{
port: 6379,
host: "172.x.x.x",
},
], {
redisOptions: {
password: "ssffvggfg",
},
});
cluster.set("foo", "bar");
cluster.get("foo", (err, res) => {
console.log(res);
});
Thanks

Related

Express-session uses Redis. When Redis stops, the request is blocked

In NestJS, I use Express-Session and use Redis as Store.
The Redis address is a load balancing address. When I offline the Redis server, I sent a new request and found that I had been loading until timeout. I want to return the response after the redis error is detected.
const RedisStore = connectRedis(session);
const redisClient = new Redis('redis://****:6379');
redisClient.on('error', (err) => {
console.error(err);
});
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.use(
session({
store: new RedisStore({ client: redisClient }),
secret: 'asdasdasd',
resave: false,
saveUninitialized: false,
cookie: { httpOnly: true, maxAge: 1000 * 60 * 10 },
}),
);
redis error
Error: connect ETIMEDOUT
at Socket.<anonymous> (/Users/code/nestjs-session/node_modules/ioredis/built/Redis.js:168:41)
at Object.onceWrapper (events.js:312:28)
at Socket.emit (events.js:223:5)
at Socket._onTimeout (net.js:474:8)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7) {
errorno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect'
}
try with redis legacy mode
const redis = createClient({ socket: { host: "localhost", port: 6379 }, legacyMode: true });

How to mock and testing an FTP Connection with Mocha

I am using the FTP library to establish an FTP connection to receive files from a specific location. I need to cover with tests mocha
const client = new Client();
const connect = {
host: 'host',
port: 21,
user: 'user',
password: 'password'
}
client.on('ready', function() {
client.list(function(err, list) {
if (err) throw err;
console.log(list);
client.end();
});
});
client.connect(connect);

Can't connect to DB using node.js

I am new to node.js and try to connect to my database. I am using VS 2019 and when debugging while connecting to the local database (which is a copy from that on the server), it works fine and return the data but when I debug it when refer to the database on the server it didn't work.
I got the following error:
ConnectionError: Failed to connect to SQL5075.site4now.net:1433 - 12924:error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol:c:\ws\deps\openssl\openssl\ssl\statem\statem_lib.c:1994:
Can anyone help? Thank you
This is my code in VS2019:
var app = require('express')();
app.get('*', (req, res) => {
var sql = require("mssql");
// config for your database
var config = {
//This connection works fine
//user: 'sa',
//password: 'xxxxxxx',
//server: 'localhost',
//database: 'DB_9BD4_info'
// this connect to the server.
user: 'DB_admin',
password: 'xxxxxxx',
server: 'SQL50.xxxxxxx.net',
database: 'DB_9BD4_info'
};
(async function () {
try {
let pool = await sql.connect(config)
let result1 = await pool.request()
.query('select * from info')
// console.dir(result1)
// send records as a response
res.send(result1);
} catch (err) {
console.log(err)
}
})();
sql.on('error', err => {
// error handler
console.log(err);
});
});
//start listening
var port = process.env.PORT || 5321;
app.listen(port, function () {
console.log('Application started on ' + new Date());
console.log("Listening on " + port);
});
I've got the same error. What worked for me was this config object:
const sqlConfig = {
server: 'server',
database: 'database',
user: 'user',
password: 'password',
pool: {
max: 10,
min: 0,
idleTimeoutMillis: 30000,
},
options: {
instanceName: 'instance name',
trustServerCertificate: true,
encrypt: false,
},
};

"Client network socket disconnected before secure TLS connection was established" error in nodemailer

I want to setup contact form, that's why I am using node mailer and postman for testing purpose but, i am receiving this error
Client network socket disconnected before secure TLS connection was established
Here is my code:
const transporter = nodemailer.createTransport({
host: 'smtp.itcarver.com',
port: 587,
secure: false,
auth: { user: 'support#itcarver.com', pass: 'xyz' },
tls: { rejectUnauthorized: false }
});
const mailOptions = {
from: 'support#itcarver.com',
to: "xyz",
subject: "subject",
text: "test",
};
transporter.sendMail(mailOptions, function(error, info) {
if (error) {
console.log(error)
res.send("error");
} else {
res.send('Email sent: ');
}
});
And here is the error:
Error: Client network socket disconnected before secure TLS connection was established
at connResetException (internal/errors.js:604:14)
at TLSSocket.onConnectEnd (_tls_wrap.js:1513:19)
at Object.onceWrapper (events.js:417:28)
at TLSSocket.emit (events.js:323:22)
at endReadableNT (_stream_readable.js:1204:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'ESOCKET',
path: undefined,
host: 'smtp.itcarver.com',
port: undefined,
localAddress: undefined,
command: 'CONN'
}
You may need to set tls maxVersion to some other than default (which is TLSv1.3). It was necessary in my case.
tls: { maxVersion: 'TLSv1.2' }

Send email using Nodemailer with GoDaddy hosted email

I am trying to send an email using nodemailer and a custom email address configured through GoDaddy. Here is a screen shot of the "custom configurations" page in c-panel:
and my code:
const nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'Godaddy',
secureConnection: false,
auth: {
user: 'info#mywebsite.com',
pass: 'mypassword'
}
});
var mailOptions = {
from: 'info#mywebsite.com',
to: 'otheremail#gmail.com',
subject: 'Sending Email using Node.js',
text: 'That was easy!',
html: '<h1>Welcome</h1><p>That was easy!</p>'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
and my error log:
{ Error: connect EHOSTUNREACH 173.201.192.101:25
at Object.exports._errnoException (util.js:1012:11)
at exports._exceptionWithHostPort (util.js:1035:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1080:14)
code: 'ECONNECTION',
errno: 'EHOSTUNREACH',
syscall: 'connect',
address: '173.201.192.101',
port: 25,
command: 'CONN' }
I've tried changing the port number, making it secure vs non-ssl, using my website address as the host, and pretty much everything else I can think of. I have successfully sent an email from the godaddy email using one of the webmail clients. Has anyone else ever encountered this or have recommendations on things to try?
I am trying to send emails using nodemailer from Google Cloud Function using GoDaddy SMTP settings. I do not have Office365 enabled on my GoDaddy hosting. None of the above options worked for me today (12 November 2019). TLS need to be enabled.
I had to use the following configuration:
const mailTransport = nodemailer.createTransport({
host: "smtpout.secureserver.net",
secure: true,
secureConnection: false, // TLS requires secureConnection to be false
tls: {
ciphers:'SSLv3'
},
requireTLS:true,
port: 465,
debug: true,
auth: {
user: "put your godaddy hosted email here",
pass: "put your email password here"
}
});
Then, I could send a test email as follows:
const mailOptions = {
from: `put your godaddy hosted email here`,
to: `bharat.biswal#gmail.com`,
subject: `This is a Test Subject`,
text: `Hi Bharat
Happy Halloween!
If you need any help, please contact us.
Thank You. And Welcome!
Support Team
`,
};
mailTransport.sendMail(mailOptions).then(() => {
console.log('Email sent successfully');
}).catch((err) => {
console.log('Failed to send email');
console.error(err);
});
you should make some changes in your transporter:
var smtpTrans = nodeMailer.createTransport({
service: 'Godaddy',
host: "smtpout.secureserver.net",
secureConnection: true,
port: 465,
auth: {
user: "username",
pass: "password"
}
});
I realize this is an old post, but just wanted to add to this since the GoDaddy SMTP server has changed, just in case someone else comes across this and has the same problem I had. The answer by #tirmey did not work for me, but this did.
let nodemailer = require('nodemailer');
let mailerConfig = {
host: "smtp.office365.com",
secureConnection: true,
port: 587,
auth: {
user: "username#email.com",
pass: "password"
}
};
let transporter = nodemailer.createTransport(mailerConfig);
let mailOptions = {
from: mailerConfig.auth.user,
to: 'SomePerson#email.com',
subject: 'Some Subject',
html: `<body>` +
`<p>Hey Dude</p>` +
`</body>`
};
transporter.sendMail(mailOptions, function (error) {
if (error) {
console.log('error:', error);
} else {
console.log('good');
}
});
Solutions proposed above seem no longer valid, none of them worked for me. Following solution works for me:
const nodemailer = require('nodemailer');
const os = require('os');
let mailerConfig = {
host: os.hostname(),
port: 25,
};
let transporter = nodemailer.createTransport(mailerConfig);
transporter.sendMail({
from: '<from>',
to: '<to>',
subject: '<subject>',
text: '<text>'
}, (err, info) => {
console.log(info);
console.log(err);
});
I could solve the problem by using this code and some points that I brought them after codes:
const smtpTransport = nodemailer.createTransport({
host: "smtp.office365.com",
secure: false,
port: 587,
auth : {
user : 'info#my-domain.com',
pass : 'Password'
}
});
const mailOptions = {
to: 'target-mail#',
subject: 'Test 01',
html: 'Body',
from : 'info#resoluship.com'
};
await smtpTransport.sendMail(mailOptions);
Don't forget to use 'from' attribute in mailOptions
Don't use ',' in your 'from' attribute
For me, the solution for production shared hosting server was completely different than for testing.
It seems no authentication or credentials are required for it to work.
I created this code from this document describing how to use an SMTP relay server. You can use this with nodemailer. GoDaddy support told me I couldn't but I don't think they know about third party tools.
https://au.godaddy.com/help/send-form-mail-using-an-smtp-relay-server-953
async function main() {
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: 'localhost', //use localhost for linux cPanel hosting
port: 25,
secure: false,
// no need for authentication
tls: {
rejectUnauthorized: false
}
});
// send mail with defined transport object
let info = await transporter.sendMail({
to: "you#youremail.com", // list of receivers
subject: `New Message from ${name}`, // Subject line
text: `yourtext`, // plain text body
html: `your text in html`, // html body
headers: {
priority: 'high'
},
from: "you#youremail.com" // sender address
});
// send success page if successful
if (res.statusCode === 200) {
res.sendFile(path.join(__dirname, 'views/success.ejs'))
}
console.log("Message sent: %s", info.messageId, res.statusCode);
}
main().catch(console.error);
The most common problem with this error is the antivirus. So disable it for 10 minutes if you are testing it locally.