ngrok icon indicating copy to clipboard operation
ngrok copied to clipboard

How can i make a tunnel for mongodb connection?

Open tngflx opened this issue 5 years ago • 2 comments

Currently I have code that look like this.

const dburl = "mongodb://username:password@localhost:27017/test"

const ssh = {
    ngrok: (proto, addr) => {
        return ngrok.connect({
            proto,
            addr,
            authtoken: config.authtoken
        }).then(url => {
            console.log('Tunnel Created -> ', url);
            logger.info(url);
            console.log(`Tunnel Inspector ->  http://127.0.0.1:${addr}`);
        }).catch(err => {
            console.error(err);
        })
    }
}
ssh.ngrok('tcp', 27017).then(() => connect())

function connect() {
    mongoose.connection
        .on('error', console.log)
        .on('disconnected', connect)
        .once('open', () => {
            console.log('MongoDB connection active')
            var io = require("socket.io")(wsLogServer);
            wsLog.connect(io)
        });
    return mongoose.connect(dburl, { useNewUrlParser: true, useUnifiedTopology: true });
}

The problem is that I keep getting localhost:27017 econn refused. It was working before this now it doesn't. I didn't change any code. Is this the proper way to setup mongodb connection through ngrok?

tngflx avatar Oct 28 '19 05:10 tngflx

What'd you end up doing?

mayeaux avatar Nov 29 '20 08:11 mayeaux

Nothing mann. Still unresolved

tngflx avatar Nov 29 '20 09:11 tngflx