How do I develop node js on localhost whilst connecting to remote mongo db

这一生的挚爱 提交于 2019-12-12 04:47:45

问题


I'm using OpenShift with node js and mongo db.

I'd like to develop updates locally and then push them to the server.

How can I develop node js locally and connect to a remote mongo db.

I've tried port forwarding. This forwards everything for some reason so runs node js server instance. Which is no good. I want to run the localhost node js.

rhc port-forward appname

This port forwads just mongodb, but if I then run node js in a separate terminal, it's unable to connect.

rhc port-forward appname -s mongodb

Do i even need port forwarding, or will the correct mongo db connection string solve this?

Hope somebody clever out there knows the answer.


回答1:


Ok, solved this.

First enable port forwarding for just mongo db.

rhc port-forward appname -s mongodb

Use a local db connection string

mongodb://admin:ABCDEFGHIJ@127.0.0.1:27017/database‌​name

Run node

node server.js

Port forwarding will forward just mongo db via localhost to it's remote location.



来源:https://stackoverflow.com/questions/42937519/how-do-i-develop-node-js-on-localhost-whilst-connecting-to-remote-mongo-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!