Node.js - Is this a good framework for frequently updated content?

As an answer to my question yesterday about Node.js and communication with clients, I am trying to understand how this will work.


Happening:

So, I have this site where content is updated very often . Suppose this time this content is a list of locations with temperature . (yes, meteorological service)

Now, every time a client checks a specific location, he or she goes to a URL like this: where matches the location identifier in my database. example.com/location/id id


Implementation:

On the loop server (every second or so) through all the locations in my (mySQL) database and checks the appropriate temperature. Then it stores this data in an array inside . Since temperatures can constantly change, it is important to keep an eye on the updates in the database. checktemps.jschecktemps.js

When the request is executed , it looks through the array with the record with id = id. He then responds with the appropriate temperature. example.com/location/idchecktemps.js


Question:

Plain text, html or ajax call is not relevant at the moment. I'm just wondering if I have this right? Node.js is a rather unusual thing to understand, so I'm trying to figure out if this makes sense ?

+3
source share
2 answers

, checktemps.js ( ) (mySQL) . checktemps.js

. ( ).

( node.js, ). :

, pubsub. , , , . ( ):

var     PORT        = 3000,
            HOST        = 'localhost',
            express = require('express'),
            io          = require('socket.io'),
            redis       = require('redis'),
            app         = module.exports = express.createServer(),
            socket  = null;

app.use(express.static(__dirname + '/public'));

if (!module.parent) {
    app.listen(PORT, HOST);
    console.log("Express server listening on port %d", app.address().port)
    socket = io.listen(app);

    socket.on('connection', function(client) {
        var subscribe = redis.createClient();
        subscribe.subscribe('pubsub'); // listen to messages from channel pubsub

        subscribe.on("message", function(channel, message) {
            client.send(message);
        });

        client.on('message', function(msg) {
        });

        client.on('disconnect', function() {
            subscribe.quit();
        });
    });
}

, redis.

, , .

+2

node.js . "/" . ajax, / . node.js , . youtube Introduction to Node.js with Ryan Dahl ( node.js), . , .

0

All Articles