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 8609957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:00:30+00:00 2026-06-12T04:00:30+00:00

I currently have a client connection event, which when fires, starts watching a file.

  • 0

I currently have a client connection event, which when fires, starts watching a file. When a second client connects, the same file is watched again. (fs.watchFile() is used)

On the client disconnection event, the file is unwatched. (fs.unwatchFile() is used) So if the first client disconnects, the file is also unwatched for the second client.

How do I work around this? I’ve tried using the listener function of fs.watchfile and fs.unwatchFile() but I don’t know how to name each listener differently on a client connect.

From what I know, creating a listener is done by assigning a variable like such:

var listener1 = function (curr, prev) {
  console.log('touched 1');
});

Then the listener can be watched or unwatched:

fs.watchfile('data.log', listener1);
fs.unwatchFile('data.log', listener1);

How do I name that listener uniquely every time a client connects? So then I can unwatch the file by listener instead of by file?

  • 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-06-12T04:00:31+00:00Added an answer on June 12, 2026 at 4:00 am

    Create an object, keyed by whatever you’re using to identify clients, whose values are the individual listeners:

    var listeners = {};
    ...
    // When client connects
    listeners[clientId] = function(curr, prev) {
    ...
    };
    fs.watchfile('data.log', listeners[clientId]);
    ...
    // When client disconnects
    fs.unwatchfile('data.log', listeners[clientId]);
    

    As a general rule, if you find yourself wanting a bunch of similarly-named variables, one for each instance of something, what you really want is a data structure like an array or object.

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

Sidebar

Related Questions

I need some help about WCF and authorization. Currently I have a client which
I have a program which monitors a TCP connection for any data and fires
I currently have a client that wants me to 'abstract' out a domain model
I currently have a datasource from a client in the form of XML, this
We currently have 4 installers for our client software: ClientSetupTest ClientSetupProduction ClientUpdateTest ClientUpdateProduction The
I currently have an archaic system of client records that I am trying to
I currently have a Firebird server on Windows and Windows desktop client applications for
I currently have a Service in Android that is a sample VOIP client so
I currently have a Gridview , And I want to use client-side validation to
I am working on an IMAP client using java mail. We currently have 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.