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.
Related
I am getting the below error when I am trying to establish a database connection in my node js application using sequelize
C:\Users\user123\Desktop\project\node_modules\tedious\lib\token\token-stream-parser.js:24
this.parser = _stream.Readable.from(_streamParser.default.parseTokens(message, this.debug, this.options));
^
TypeError: _stream.Readable.from is not a function
I am in initial stage of creating an application. Where I have just tried to create a database connection, for which I have created three files
index.js
var dotenv = require("dotenv").config().parsed;
var customEnv = require("custom-env");
customEnv.env("development").env();
var express = require("express");
const helmet = require("helmet");
var cookieParser = require("cookie-parser");
const app = express();
app.use(helmet());
app.use(cookieParser());
require("./db.js");
httpserver = require("http").createServer(app);
httpserver.timeout = 0;
httpserver.listen(3457, async () => {
connectedEmitter.on("connectedDbs", () => {
console.log(` ----- SERVER LISTENING ON PORT `);
});
});
db.js
const Sequelize = require('sequelize');
const eventEmitter = require('events');
global.connectedEmitter = new eventEmitter()
global.sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASS, {
host: process.env.DB_HOST,
port: 1433,
dialect: process.env.DB_DIALECT,
ssl: false,
dialectOptions: {
ssl:false
},
logging:false,
pool: {
max: 20,
min: 0,
idle: 30000
}
});
sequelize.authenticate().then(() => {
console.log(`${process.env.DB_NAME} - Connection has been established successfully.`);
global.connectedEmitter.emit('connectedDbs')
}).catch((err) => {
console.error(' - Unable to connect to the database:', err);
});
.env (I am giving dummy credentials as I cannot provide original credentials)
# ################################## Database Credentials ##############################################
DB_NAME=mydb
DB_USER=username
DB_PASS=password
DB_HOST=hostname
DB_DIALECT=mssql
Can anyone please tell me why am I getting the error mentioned. Where have I made the mistake in setting the database connection. Please help.
I also faced this issue. Turns out tedious had issues with node versions below 12, and my production app service was running on node 10.
GitHub link that mentions this
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'
}
I'm trying to create an HTTPS server using node.js and and docker. I have already created the certificates and configured the app. But I don't know how to run the image docker. I am trying this, but it is not working.
Does anyone know how to do this?
sudo docker run --name cont_docker -p 443:3333 --link my-mongo:my-mongo user/docker_app
I am not using docker-compose
---> EDIT <---
The container is not crashing. It is not responding. In the app I get 'couold not connect to server'. I think it is not binding the port
const express = require('express');
const getRootPath = require('../helpers/get-root-path.helper');
var fs = require('fs');
const https = require('https'); // REQUIRE HTTPS
const privateKey = fs.readFileSync('private/key/path', 'utf8');
const certificate = fs.readFileSync('cert/key/path', 'utf8');
let _express = null;
let _config = null;
let _router = null;
let _credentials = null;
class Server {
constructor({ config, router }) {
_router = router;
_config = config;
_credentials = { privateKey: privateKey, certificate: certificate } // ADD CREDENTIALS
_express = express();
}
/*
This methods returns a promisse that will be in charge of initate the server.
*/
start() {
_express.use(express.static(`${this.getRootPath(__dirname)}/public`))
_express.use(_router)
_express.engine('html', require('ejs').renderFile)
_express.set('view engine', 'html')
return new Promise(resolve => {
const server = https.createServer(this._credentials, _express)
server.listen(_config.port, () => {
console.log(`App running on port ${_config.port}`)
resolve()
})
})
}
getRootPath(path) {
return getRootPath(path)
}
}
module.exports = Server
---> APP.JS <---
const container = require('./src/startup/container')
const server = container.resolve("app")
const { db_host, db_database } = container.resolve("config")
const mongoose = require('mongoose')
mongoose.set("useCreateIndex", true)
mongoose
.connect(`mongodb://${db_host}/${db_database}`, { useUnifiedTopology: true, useNewUrlParser: true, useCreateIndex: true, useFindAndModify: false })
.then(response => {
console.log(`Connected to Mongo! Database name: "${response.connections[0].name}" on "${response.connections[0].host}"`)
server.start()
})
.catch(console.log)
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.
I am trying to use HTTP/2. My express version is 5.0.0-alpha.2, http2 version is 3.3.4.
I suppose http2 should work well with express 5.
const http2 = require('http2');
// const http2 = require('spdy'); // using spdy package here, everything works perfect
const options = {
key: fs.readFileSync(path.join(__dirname, 'private', 'server.key')),
cert: fs.readFileSync(path.join(__dirname, 'private', 'server.crt'))
};
const server = http2
.createServer(options, app)
.listen(3000, err => {
if (err) throw new Error(err);
// I can see "Listening..." message, which means the server starts running well.
console.log('Listening...');
});
The server starts running well, but when I open client website, it gives me this error in the terminal:
_stream_readable.js:512
dest.end();
^
TypeError: dest.end is not a function
at Stream.onend (_stream_readable.js:512:10)
at Stream.g (events.js:286:16)
at emitNone (events.js:91:20)
at Stream.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:975:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
It seems node-http2 has not been supported by Express yet.
Please track this issue Support for module http on github.
In the meanwhile, you can stay with node-spdy.
const spdy = require('spdy');
const options = {
key: fs.readFileSync(path.join(__dirname, 'private', 'server.key')),
cert: fs.readFileSync(path.join(__dirname, 'private', 'server.crt'))
};
const server = spdy
.createServer(options, app)
.listen(3000, err => {
if (err) throw new Error(err);
console.log('Listening...');
});
With Express 5.0 we have another solution :
express = require( 'express' ), //Web framework
// Solution
express.request.__proto__ = http2.IncomingMessage.prototype;
express.response.__proto__ = http2.ServerResponse.prototype;
// Create app for server http/2
var apph2 = express();
And this is the server code :
var
application_root = __dirname,
express = require( 'express' ), //Web framework
http2 = require('http2')
logger = require('morgan')
fs = require('fs')
constants = require('constants');
// Bunyan logger
var bunyan = require('bunyan');
var app = require('./apps/app_name');
var bunlog = bunyan.createLogger({name: "brqx_app"});
var credentials = {
// log : bunlog ,
key : fs.readFileSync('/etc/letsencrypt/live/domain/privkey.pem' ),
cert : fs.readFileSync('/etc/letsencrypt/live/domain/fullchain.pem' ),
ca : fs.readFileSync("/etc/letsencrypt/live/domain/chain.pem" ),
dhparam : fs.readFileSync("/etc/letsencrypt/archive/domain/dh1.pem" ),
secureOptions: constants.SSL_OP_NO_SSLv3 | constants.SSL_OP_NO_SSLv2
};
// Configure server
server = http2.createServer( credentials , app);
server.listen(PORT , function () {
console.log('Started Brqx http/2!');
} )
I hope these easy lines helps to people.
One thing is important when we search information on Internet is the date of test when code was tested : 2017 - October.
Regards.
Ricardo/Brqx.