简体   繁体   中英

How to integrate derby.js with express.js in node.js?

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM