Search code examples
mysqlangularjsnode.jsmongodbnode-mysql

Nodejs on Server Ajax/http calls not reading new data Mongodb


I've recently started with pushing my locally tested Node,mongo, angularjs sites to live environments hosted on DigitalOcean.

I'm having inconsistency with ajax/http calls. on my Local machine, I am able to do http request and update an angularjs variable and this in return populates the html on the frontend. all works Great! now testing this on my server with same envireontment setup, the only time the variable load new data is when i refresh the page.

For example (not my actualy code):

Nodejs - app.js:

app.get('/getlist', requiredAuthentication, function(req, res) {
    list.find({'username':req.session.user.username}, function(err,list) {
    res.send(list);
});});

Angularjs - angular_app.js:

$scope.onClick = function (points, evt) {
    $http.get('/getlist').then(function(response) {
     $rootScope.list = response;});
};

Jade - home:

li(ng-repeat="row in list")

So like I said, this works perfectly on my local machine, but on my server I must refresh my page to load new data, it's as though my variable gets cached on the server.

Any idea would help.

Thanks.!

------- UPDATE - testing v0.1 --------

So after some intensive testing here is what I've found, but still no fix.

If I add new data via an http post, and I go look in my mongo db, I see the new data. Then when I click on the ng-click to retrieve the new data via HTTP, it doesn't return the new data, and is stuck on the old.

If I leave the page open for 10mins, and then click the button, it retrieves the new data, this is such a shlep.

Sounds like cache, but why des it work perfectly on my local?

When looking at the console > network > status. it is code 304, and this means nothing changed?

------- UPDATE - testing v0.2 --------

I've now tested the return data with a log in the console and I did the GET with ajax jQuery, and I'm getting the same issue/behaviour, it's stuck on the same collection of data, so my conclusion must be that node.js is causing the issues.

------- UPDATE - testing v0.3 --------

Okay so I've completely stopped mongo and switched everything to mysql using node-mysql. once again, on my local it works like a machine and on my actual server its laggy with reading new data.

I used Sequal PRO to access mysql and I started adding new entries to a table. Opening my web url in the brower it Immediately showed the new entries. But after that, adding new entries or deleting entries only showed affect in 10mins or so.

So my conclusion is that Nodejs is caching like a mother, anyone know more bout this? am i really the only one every to experience this?


Solution

  • My conclusion to this issue was that port 80 was somehow caching the content of a page and will only load new data with a page refresh.

    I upgrade Node and used latest Express. And I'm running my web app on a custom port, all is working now.