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);
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.