Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mysql = require('mysql2');
- var Client = require('ssh2').Client;
- var ssh = new Client();
- var db = new Promise(function (resolve, reject) {
- ssh.on('ready', function () {
- ssh.forwardOut(
- '127.0.0.1',
- 12345,
- '127.0.0.1',
- 3306,
- function (err, stream) {
- if (err) throw err;
- let connection = mysql.createConnection({
- host: '127.0.0.1',
- user: 'username',
- password: 'password',
- database: 'test',
- stream: stream
- });
- connection.connect(function (err) {
- if (!err) {
- resolve(connection)
- } else {
- reject(err);
- }
- });
- });
- }).connect({
- host: 'hostname',
- port: 22,
- username: 'username',
- password: 'password'
- });
- });
- module.exports = db;
- var database = require('./db');
- module.exports.getcats = (function(req, res) {
- database().then(function (connection) {
- connection.query("SELECT * FROM listUnit", function (error, results, fields) {
- if (error) {
- console.log(error);
- return;
- }
- res.write(results);
- });
- });
- });
Add Comment
Please, Sign In to add comment