4

I am using express framework for my Node App. I need to have some real time updates like notifications in facebook. What I need is integrate derby.js(which is framework build on the top of express) only for real time notification triggering in express App. How can I accomplish this task?

Expressjs syntax I am using

app.get('/', function(req, res){
   //other things as fetch query 
   res.render('index', { notificationcount : 0 });
});

Above thing will take notification count from database and displayed in view.

Derbyjs sample syntax for real time update

app.view.make('Body'
, 'Notications: <div>{notificationcount}</div>'
);
app.get('/', function (page, model) {
  // Subscribe specifies the data to sync
  model.subscribe('notificationcount', function () {
    page.render();
  });
});

What I need is only one section(box with notification count) from express rendered view page needs come from derby. So that the box will updated on real time updates on Database.

How we can integrate derby view in express? Is it possible?

Justin John
  • 9,223
  • 14
  • 70
  • 129

2 Answers2

2

Derby is a full-featured alpha framework for building real-time apps. It seems like you only need a small amount of real-time for specific functionality. I'd recommend just using socket.io or sockjs - no need to integrate an entire framework for one tiny use case.

switz
  • 24,384
  • 25
  • 76
  • 101
  • 1
    It's not only one tiny case, there are some other cases also. To make my question more clearer, I only focuses on trigerring notifications in my post. My question is how we can parallely integrate derby with express? – Justin John Apr 14 '13 at 15:48
  • 1
    Derby is built on express. If you really want to use Derby, just use Derby as you would normally. Since it's built directly on top of express, you can do anything in express that you would want to do irregardless of Derby's presence. – switz Apr 14 '13 at 18:09
  • 1
    it is "regardless", not "irregardless" -- Sorry, but that drives me crazy :-) – Carol Skelly Jul 16 '13 at 18:51
  • @Skelly Actually, [the dictionary says](http://www.merriam-webster.com/video/0037-irregardless.html) irregardless is a word too. – user456584 Jun 19 '14 at 02:53
0

Well, not sure where you bought the syntax, but

  • change {notificationcount} to {{notificationcount}} ...

and render the page correctly

page.render('index', { notificationcount : 0 });

whenever your model changes, site will change live. You should install and study the examples :: https://github.com/codeparty/derby-examples

sebilasse
  • 4,278
  • 2
  • 37
  • 36