Question: I've got nginx to run my (node.js/react) application on the server. But I can't seem to connect to the database. 

In the nginx.conf file I've added the following inside http.

```
http {
    ...
    server {
        listen       80;
        server_name  localhost;
    ...}
...}

```

And above the http section I have the following,

```
stream {
    server {
        listen  4000;
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass    stream_mongo_backend;
    }

    upstream stream_mongo_backend {
      server 127.0.0.1:27017;
  }
}

```

I start the nginx server, the application runs on localhost, opens up the login page but I can't login because it's still not connected to the database (mongodb). 
I'm not sure if I've got my port numbers wrong or if I'm missing some configuration line inside nginx.conf. 

EDIT: Ok, I had it wrong before. I wasn't supposed to connect to mongodb at this point. I was supposed to connect to the backend server of my application which would run at 4000. So now I've added a new location for /api/ inside http and proxied all requests to 4000. I still have one question though. I have to run my backend server separately for this to work. For the frontend I've created a folder and put all my build files in there so nginx starts up the webserver from there. Doing the same for the backend did not start up the server. Is there a way to get nginx to start the backend server as well? 
Also can I get the frontend to run directly without the build files ? Like node would with npm start?

Answer: 
You wrote `current_profit =+finance.getProfit()` where you meant `current_profit += finance.getProfit()`. You just assign the value, with unary `+` called on it, which does nothing. The operator of adding a value to the previous value is `+=`.
The corrected method, the problem was =+, changed into +=

```
public MutableLiveData<Integer> getProfit() {

   //the method getFinanceList returns a financeList of size 2 as  illustrated above in the debug code.

    getFinanceList();

    int current_profit = 0;

    for (int i = 0; i < financeList.size(); i++) {
        Finance finance = financeList.get(i);
        current_profit +=finance.getProfit();
    }

    Log.d(TAG, "getProfit: " + current_profit);

    MutableLiveData<Integer> profit_data = new MutableLiveData<>();
    profit_data.setValue(current_profit);

    return profit_data;
}

```