Can Dirik Can Dirik - 1 year ago 99
Node.js Question

How do i connect online database with set NODE_ENV=production && nodemon?

I have 2 databases. 1 of them on local. And other one on When i start app with nodemon, i can connect local database. But when i want to connect database that on mlab. It comes out with problem. I use this :

set NODE_ENV=production && nodemon.

and after this i still get local connection. And this code is in db.js file.

var mongoose = require('mongoose');
var dbURI = 'mongodb://localhost/WiFiBuddy';
if (process.env.NODE_ENV === 'production') {
dbURI = process.env.MONGOLAB_URI;

and by the way i can connect to online database with mongoshell. But can't connect with command line.

dan dan
Answer Source

According to an issue on the nodemon Github repo, the space after "production " could be causing the issue. So if you use:

set NODE_ENV=production&& nodemon.

Then the production if statement should be triggered

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download