0

I am working on a project builded with NodeJs (ExpressJS) and AngularJS (Front-end).

I have a map which display geoJSON polygons on it. The color of the polygon must be read from a real-time data file. The colors might be updated every second.

For the moment, angularJS is making a $http.get request every second

$interval(function(){
    MapService.getRealTimeData().then(function(resp){
        $scope.showDataError = false;
        $scope.geojson = createGeoJsonObject(resp.data);
    }, function(err){
        $scope.showDataError = true;
    });
}, 1000)

The $http calls a ExpressJS API which read the file and send back a geojson.

Is it a good way to do it ? Should I change it and use Socket.io ? Should the server send the data when the real-time data file changes ?

EDIT

Thanks for the comment, I will keep this way of working with the call every second. Sorry for asking this kind of "question" but thanks for your help.

Weedoze
  • 13,683
  • 1
  • 33
  • 63
  • 1
    I assume, your question will be closed soon as it is `primarily opinion-based`, but sure I guess using websocket with socket.io is better option for your case, look http://stackoverflow.com/q/6806263/972240 for more info. – gevorg Jun 30 '16 at 12:25
  • I misswrote my question then sorry. I just want to know if my way of doing it can lead to problems or if it is not a good way of working – Weedoze Jun 30 '16 at 12:26

1 Answers1

0

How often will there be updates?

If it is close to 1000ms anyways, you can just keep doing what you do now, no reason to use Socket.Io, unless you want to implement more complex features in an easy way; It seems fine.

Alexander
  • 1,554
  • 2
  • 16
  • 23
  • Every second I am calling the server which read a file and override a json file to send it back – Weedoze Jun 30 '16 at 12:31
  • What do you mean by more complex features ? I need to create another page which will also read the same file every second – Weedoze Jun 30 '16 at 12:32
  • With complex feature I mean that if every visitor would have his own "map", and you need "rooms" for each person. So you just update the file once a second? Then you might as well do a request once a second. Like gevorg said, I think you can better avoid these type of questions, you aren't really having a direct problem that we could answer. – Alexander Jun 30 '16 at 12:36
  • 1
    Okok thx ! I will edit my question to mark that is not a real question ! Thx for your help dude – Weedoze Jun 30 '16 at 12:37