问题描述
我正在使用带有节点js和mongo db的OpenShift.
I'm using OpenShift with node js and mongo db.
我想在本地开发更新,然后将其推送到服务器.
I'd like to develop updates locally and then push them to the server.
如何在本地开发node js并连接到远程mongo数据库.
How can I develop node js locally and connect to a remote mongo db.
我尝试了端口转发.由于某种原因,这会转发所有内容,因此可以运行节点js服务器实例.不好我要运行localhost节点js.
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
此端口仅禁止mongodb,但如果我随后在单独的终端中运行node js,则无法连接.
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
我什至需要端口转发,还是将正确的mongo db连接字符串解决此问题?
Do i even need port forwarding, or will the correct mongo db connection string solve this?
希望外面有一个聪明的人知道答案.
Hope somebody clever out there knows the answer.
推荐答案
好,解决了这个问题.
首先仅对mongo db启用端口转发.
First enable port forwarding for just mongo db.
rhc port-forward appname -s mongodb
使用本地数据库连接字符串
Use a local db connection string
mongodb://admin:[email protected]:27017/databasename
运行节点
node server.js
端口转发将仅通过localhost将mongo db转发到它的远程位置.
Port forwarding will forward just mongo db via localhost to it's remote location.
这篇关于如何在连接到远程mongo db的同时在localhost上开发Node js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!