1

I am working on project where I want to give notification like facebook. i.e. when someone comments on others profile or like any link on others profile. I want to use nodejs for real time push notification.

These data of comments, likes are stored in the mysql database in "Notification table" via ajax request or by posting the form to php.I found many tutorials of nodejs on net for the real time push notifications but unfortunately they talk about keeping watch on file and emits the notification when file is updated.

does anybody knows how to keep watch on the mysql table, so whenever, any data is inserted in the table, it emits the notification. I am not getting any way what kind of code I should write in nodejs.

Please let me know if more explanation is needed.

Thanks in advance.

2
  • Did you able to complete your project ? Commented Oct 28, 2014 at 4:40
  • yes. I have completed it Commented Dec 23, 2014 at 9:53

2 Answers 2

1

You can use node.js with a mysql library to poll your database for new notifications, which I think is what you're trying to do. I've never done that specific task personally, but I know it's achievable.

In terms of what kind of code you need to write, try looking up "Node Middleware Tutorials" with perhaps some variations that include MySQL in the search query and you'll find at least an idea of what you should be looking for.

If I can I will update this answer with more specific code samples to get you moving in the right direction.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks Brian, I will look up as per your suggestion.I want is that, is it possible that whenever mysql table is updates by new records, can I get directly that updates by nodejs, so as I do not have to make request every minutes just like doing traditional ajax request.
Yes you can use Socket.io to push updates to the browser, however you will likely still need to use Node to poll your database for changes, unless you're already using Node to insert the notification data into your database.
Ok brian, that means I have to set timeout in my function in nodejs and periodically it will fire select query on the mysql. but will it be optimized solution?
The only solution that's better would be to push the notification when it is inserted into the database. There's no way for MySQL to automagically send push notifications for you, so if you're not doing the push at the same time as the insert then you'll need some kind of loop to watch for changes in the table.
Ok brian, I just wanted to do optimized solution so as server gets less load. I will check out both options. Thanks for the help.
0

You can use nowjs and add on the after save (if you are using an mysql active record) to notify the client with this package.

On the server

var httpServer = require('http').createServer(function(req, response){ /* Serve your static files */ })
httpServer.listen(8080);

var nowjs = require("now");
var everyone = nowjs.initialize(httpServer);

everyone.now.logStuff = function(msg){
    console.log(msg);
}

On the client

<script type="text/javascript" src="http://localhost:8080/nowjs/now.js"></script>

<script type="text/javascript">
  now.ready(function(){
    // "Hello World!" will print on server
    now.logStuff("Hello World!");
  });
</script>

For more information take a look at the examples

5 Comments

Thanks Norman, I will look at this nowjs also. sorry for the late reply.
nevermind, if this answer your question mark it as aswered... regards
It looks like nowjs has been abandoned by its developers (at least for now.) Do you know of any suitable replacement for it? groups.google.com/forum/?fromgroups=#!topic/nowjs/FZXWZr22vn8
thanks, I've not been noticed about that the author not maintain it anymore, but hope some members of the community will maintain it
I know this is a bit old - but socket.io seems the de facto standard these days.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.