NodeMailer through error connect ECONNREFUSED 127.0.0.1:465 - node.js

I try many solutions but none of them work. I will use this to send mail to everyone through custom domain mail who are login using my app
I have used the following js code in index.js to integrate app and adapter
const express = require( 'express' );
const app = express();
const port = 5000;
const nodemailer = require( 'nodemailer' );
let transporter = nodemailer.createTransport( {
service: 'smtp.CustomDomain.mail',
port: 465,
secure: false,
auth: {
user: 'XYC#CustomDomain.com',
pass:'123'
}
} )
let message = {
from: "XYC#CustomDomain.com",
to: "XYZ#gmail.com",
subject: "Message title",
text: "Plaintext version of the message",
html: "<p>HTML version of the message</p>"
};
app.get( '/', (req,res) =>
{
transporter.sendMail( message, (error,info) =>
{
if ( error ){
console.log("Something went wrong",error)
}
if ( info )
{
console.log("Mail send successfully")
}
})
} )
app.listen( port, () =>
{
console.log("Server is running on port "+port)
})
Here is the error message
Server is running on port 5000
Something went wrong Error: connect ECONNREFUSED 127.0.0.1:465
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
errno: -4078,
code: 'ESOCKET',
syscall: 'connect',
address: '127.0.0.1',
port: 465,
command: 'CONN'
}

Related

PostgreSQL error: `Error: connect ECONNREFUSED 127.0.0.1:5432`

I'm trying to make a request to postgreSQL from a Node and Express server on localhost. But I keep getting this error Error: connect ECONNREFUSED 127.0.0.1:5432 when trying to open localhost:8000/todos - not sure why.. I changed the username to 'postgres' (which is the defualt username), password, host, database name and port are all correct.. I can check the todos using SELECT * FROM todos; however, the app just breaks and gives me that code. I made sure that the server is running. I started it in services, and I can check the content of todos (which I manually added) in the SQL shell. Any ideas on why this is happening? I've gone thru all the other pages with similar issue, but I'm pretty new to postgreSQL overall and I'm unable to find an answer. I'm not using docker.
this is the exact error in the console:
Server runnnig on PORT 8080
Error: connect ECONNREFUSED 127.0.0.1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1487:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 5432
}
main server.js
const PORT = 8080;
const express = require("express");
const app = express();
const pool = require("./db");
app.get("/todos", async (req, res) => {
try {
const todos = await pool.query("SELECT * FROM todos");
res.json(todos.rows);
} catch (err) {
console.error(err);
}
});
app.listen(PORT, () => console.log(`Server runnnig on PORT ${PORT}`));
db.js file where the connection is coming from
const Pool = require("pg").Pool;
require("dotenv").config();
const pool = new Pool({
user: "postgres",
password: process.env.PASSWORD,
host: "localhost",
port: 5432,
database: "todoapp",
});
module.exports = pool;

can't connect on minio with node js

i tried to connect on minio with node js using minioClient
this is my code
Minio.js
const Minio = require('minio')
const minioClient = new Minio.Client({
endPoint: 'xxxxxx',
port: 9000,
useSSL: true,
accessKey: 'xxxxxx',
secretKey: 'xxxx'
});
module.exports = minioClient
fileupload.js
const minioClient = require('../config/connection/Minio')
module.exports = minioUpload = {
upload: async(req, res) => {
if (req.file) {
var metaData = {
'Content-Type': 'application/octet-stream',
'X-Amz-Meta-Testing': 1234,
'example': 5678
}
var originalname = req.file.originalname.split(' ');
const fileName = originalname.join('_');
try {
// Using fPutObject API upload your file to the bucket maztou.
minioClient.putObject('maztou', fileName, req.file.buffer, metaData, function(err, etag) {
if (err) return console.log(err)
return res.status(201).json('File uploaded successfully.', fileName)
});
} catch (err) {
console.log(err, '<== ERROR');
}
}
}
}
router.js
const express = require('express')
const minioUpload = require('../controllers/fileupload')
const router = express.Router()
const multer = require('multer')
router.route('/uploads').post(multer({ storage: multer.memoryStorage() }).single("file"), minioUpload.upload)
module.exports = router
And the server return this :
Error: connect ETIMEDOUT XXXX:9000
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
errno: -60,
code: 'ETIMEDOUT',
syscall: 'connect',
address: 'XXXX',
port: 9000
}
Can some one help me for this issus, i'have already read all the documentation about minioClient , all my setup is good, and i have. this issus !
The timeout indicates that the client cannot connect to the server. You should check if the endpoint, port and credentials passed to MinIO client are correct and turn off useSSL if TLS is not enabled. If your MinIO server is running in docker, you may want to check if the port is exposed.

problem about connecting to my Postgres with node.js through knex

I am facing this problem with connecting to my Postgres with node.js through knex. I am trying this for the first time and I ask humbly to help me solving the issue. please help me.
My code is the following. Every time I make a request, PostgreSQL doesn't connect so nothing happens.
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
const bcrypt = require('bcrypt-nodejs');
const cors = require('cors');
const knex = require('knex')
const db = knex({
client: 'pg',
connection: {
host: '127.0.0.1',
user: 'postgres',
password: '',
database: 'smart-brain'
}
});
db.select('*').from('users').then(console.log).catch(console.log);
app.use(cors());
app.post('/signin', (req, res) => {
if (req.body.email === database.users[0].email &&
req.body.password === database.users[0].password) {
res.json('success');
} else {
res.status(400).json('error logging in');
}
})
app.post('/register', (req, res) => {
const {
name,
email,
password
} = req.body;
db('users')
.returning('*')
.insert({
email: email,
name: name,
joined: new Date()
})
.then(respons => {
res.json(response);
}).
catch(err => res.status(400).json('unable to register'))
})
app.listen(3000, () => {
console.log('app is running on the port 3000');
});
and the response is these on npm
Error: connect ECONNREFUSED 127.0 .0 .1: 5432
at TCPConnectWrap.afterConnect[as oncomplete](net.js: 1141: 16) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 5432
}
If you are in Ubuntu, then go to the following folder.
/etc/postgresql/{your_pg_version}/main
Or If you are in Windows, then go to the following folder,
C:\Program Files\PostgreSQL\{your_pg_version}\data\
Open the file pg_hba.conf to write with SuperUser/Administrative permission,
Go to the bottom, and put trust at the end of following lines.
# Database administrative login by Unix domain socket
local all postgres trust
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
After that, restart your PostgreSQL server and try again with your code.

How do I communicate between microservices?

I have the following code in one microservices that calls another:
axios.get('http://localhost:4210/usermicroservice/heartbeat')
.then(function(resp) {
console.log('USER HEARTBEAT CALLED ')
})
.catch(function(error) {
console.log('USER HEARTBEAT ERROR ', error)
})
In the called microservice I have the following code:
server.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
next();
})
server.get('/usermicroservice/heartbeat', (req, res) => {
console.log('\n*** USER MICROSERVICE CALLED ***')
res.json({});
})
const PORT = 4210;
server.listen(PORT, () => {
console.log(`hsupp01 UserMicroservice server running on port: ${PORT}`)
})
I get the following error:
{ Error: connect ECONNREFUSED 127.0.0.1:4210
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 4210,
I am able to accessed the called microservice from Postman using the same url:
http://localhost:4210/usermicroservice/heartbeat
The error message does not capture the problem but the code below had to be executed within an asynchronous block.
axios.get('http://localhost:4210/usermicroservice/heartbeat')
.then(function(resp) {
console.log('USER HEARTBEAT CALLED ')
})
.catch(function(error) {
console.log('USER HEARTBEAT ERROR ', error)
})

heroku eureka-js-client node- Spring Cloud Netflix Support -

What I want to achieve is:
registering a node.js service in my eureka-server in heroku.
So far i can register a regular eureka-client in my eureka-server in heroku, without problems. But i am getting really confused with the configuration when try with node.js service...
I thought eureka-js-client was the solution, no success so far...
Code below.
const express = require('express');
const path = require('path');
const port = process.env.PORT || 3090;
const app = express();
app.use(express.static(__dirname));
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'index.html'))
});
const Eureka = require('eureka-js-client').Eureka;
const eureka = new Eureka({
instance: {
app: 'sheila',
hostName: 'localhost',
ipAddr: '127.0.0.1',
statusPageUrl: 'http://localhost:5000',
healthCheckUrl: 'http://localhost:5000/health',
port: {
'$': 5000,
'#enabled': 'true',
},
vipAddress: 'myvip',
dataCenterInfo: {
'#Class': 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo',
name: 'MyOwn',
},
},
eureka: {
host: 'localhost',
port: 8761,
servicePath: '/eureka/apps/',
},
});
eureka.logger.level('debug');
eureka.start(function(error){
console.log(error || 'complete');
});
// ------------------ Server Config --------------------------------------------
var server = app.listen(5000, function () {
var port = server.address().port;
console.log('Listening at %s', port);
});
First i've tried locally after running docker run -it -p 8761:8761 springcloud/eureka on my docker console. But i get this error:
Problem making eureka request { [Error: connect ECONNREFUSED 127.0.0.1:8761]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 8761 }
if i run it as it is from a heroku service, It does not execute :( :(
I also tried by substituting the host for the url of my heroku eureka server, but then i get 401 or 404 errors. The eureka server requires a password which i added in my heroku client js .
Any ideas?
You need to include an instanceId which should be a unique identifier of this instance.
const eureka = new Eureka({
instance: {
instanceId:'sheila',
app: 'sheila',
hostName: 'localhost',
ipAddr: '127.0.0.1',
statusPageUrl: 'http://localhost:5000',
healthCheckUrl: 'http://localhost:5000/health',
port: {
'$': 5000,
'#enabled': 'true',
},
vipAddress: 'myvip',
dataCenterInfo: {
'#Class': 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo',
name: 'MyOwn',
},
},
eureka: {
host: 'localhost',
port: 8761,
servicePath: '/eureka/apps/',
},
});

Resources