Search code examples
javascriptnode.jsrefreshpugpartial-page-refresh

Jade #{user.username} Partial Page Refresh


I'm using https://github.com/sahat/hackathon-starter/tree/es6 which leverages Jade in an ExpressJS & MongoDB NodeJS environment. My questions is how can I update #{event.location} && #{event.city} in Front-end if they change inside MongoDB in the back-end?

I do not want to refresh the entire website in order for #{event.location} and #{event.city} to be updated in the front-end.

Could someone please explain how to do this or if there is a better way of achieving this? Maybe with Socket.IO or some other way. I'm fairly new to Node, JS, Jade etc and can't even grasp a decent way of refreshing part of the page with JADE....

Thank you in advance for your help ! Kudos


Solution

  • Express/Jade can only render the page once from backend when the HTTP request comes.

    If you have to update the data on frontend, you will have to use different strategy depending on how your data is updated.

    If your data in the backend is updated via the same frontend or at known time you can use AJAX calls to server and fetch the values intermittently.

    If data is updated via a different channel then socket.io would be the way to go. You can emit events from the backend on data change and receive the events on frontend app and update the data fields only using javascript bindings.

    If you have too many manipulations of data to be done I would suggest using a frontend framework from the likes of Angular or Meteor.