Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
sequelize with tunnel-ssh
// sequelize config
var sequelize = new sequelize('database', 'user', 'pass', {
host: '127.0.0.1',
dialect: 'mysql',
port: 3306,
pool: {
max: 10,
min: 0,
idle: 20000
}
});
// tunnel config
var config = {
user:'user',
host:'sshhost',
port:22,
dsthost:'127.0.0.1',
dstport:3306,
srchost:'127.0.0.1',
srcport:3306,
localhost:'127.0.0.1',
localport: 3306,
privatekey: require('fs').readfilesync('/path/to/key')
};
var tunnel = require('tunnel-ssh');
// initiate tunnel
tunnel(config, function (error, server) {
//....
if(error) {
console.error(error);
} else {
console.log('server:', server);
// test sequelize connection
sequelize.authenticate().then(function(err) {
console.log('connection established');
}).catch(function(err) {
console.error('unable establish connection', err);
})
}
})
@nandhaepn

This comment has been minimized.

Copy link

@nandhaepn nandhaepn commented Apr 19, 2021

var config = {
username:'user'
host:'sshhost',
port:22,
dstHost:'127.0.0.1',
dstPort:3306,
srcHost:'127.0.0.1',
srcPort:3306,
localHost:'127.0.0.1',
localPort: 3306,
privatekey: require('fs').readfilesync('/path/to/key')
};
we need to change in camel case like above and "user" to "username"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment