Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6051509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:49:38+00:00 2026-05-23T07:49:38+00:00

As a follow-up to my question yesterday about Node.js and communicating with clients, I’m

  • 0

As a follow-up to my question yesterday about Node.js and communicating with clients, I’m trying to understand how the following would work.


Case:

So, I have this website where content is updated very frequently. Let’s assume this time, this content is a list of locations with temperatures. (yes, a weather service)

Now, every time a client checks for a certain location, he or she goes to a url like this: example.com/location/id where id corresponds to the id of the location in my database.


Implementation:

At the server, checktemps.js loops (every other second or so) through all the locations in my (mySQL) database and checks for the corresponding temperature. It then stores this data is an array within checktemps.js. Because temperatures can change all the time, it’s important to keep checking for updates in the database.

When a request to example.com/location/id is made, checktemps.js looks into the array with a record with id = id. Then, it responds with the corresponding temperature.


Question:

Plain text, html or an ajax call is not relevant at the moment. I’m just curious if I have this right? Node.js is a rather unusual thing to get a grasp on, so I try to figure out if this is logical?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:49:38+00:00Added an answer on May 23, 2026 at 7:49 am

    At the server, checktemps.js loops
    (every other second or so) through all
    the locations in my (mySQL) database
    and checks for the corresponding
    temperature. It then stores this data
    is an array within checktemps.js

    This is extremely inefficient. You should not be doing looping(every other second or so).

    Modules

    Below I would try and make a list of the modules(both node.js modules as other modules) I would use to do this efficient:

    • npm is a package manager for node. You can use it to install and publish your node
      programs. It manages dependencies and does other cool stuff.

      I hope sincerely that you already know about npm, if not i recommend you to learn about it as soon as possible. In the beginning you just need to learn how to install packages, but that is very easy. You just need to type npm install <package-name>. Later I would really like to advice you to learn to write your own packages to manage the dependencies for you.

    • Express is a High performance, high class web development for Node.js.

      This sinatra-style framework from TJ is really sweet and you should read the documentation/screencasts available to learn it’s power.

      Socket.IO aims to make realtime apps possible in every browser and
      mobile device, blurring the
      differences between the different
      transport mechanisms.

    • Redis is an open source, advanced
      key-value store. It is often referred
      to as a data structure server since
      keys can contain strings, hashes,
      lists, sets and sorted sets.

      Like Raynos said this extremely fast/sexy database has pubsub semantics, which are needed to do your question efficiently. I think you should really play with this database(tutorial) to appreciate it’s raw power. Installing is easy as pie: make install

    • Node_redis is a complete Redis client for node.js. It supports all Redis commands, including MULTI, WATCH, and PUBLISH/SUBSCRIBE.

    Prototype

    I just remembered I helped another user out in the past with a question about pubsub. I think when you look at that answer you will have a better understanding how to do it correctly. The code has been posted a while back and should be updated(minor changes in express) to:

    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();
            });
        });
    }
    

    I have compressed the updated code with all the dependencies inside, but you while still need to start redis first.

    Questions

    I hope this gives you an idea how to do this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Kind of a follow up to a question from yesterday. I have a hash
this is actually a follow up to a question I asked yesterday about problems
This is a follow up to a question that was asked yesterday. I have
A follow on from the question I asked yesterday. I have a paging scrollView
This is a follow-up to my question from yesterday . I have Scott Meyers'
As a follow-up question to the one posted yesterday, Memory consumption of a pointer
A follow-up question to my answer about editing GitHub pull-requests asked whether editing the
This is a follow up question to a previous question I asked about calculating
I have a follow-up question to this one . I created a new form,
This is a follow-up to my question yesterday . The function adds to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.