How to stream the date and time from the server via sockets? that is, every second send the correct date and time to the client

also interested in how to hang the handler, which will notify when a certain file changes? that is, a callback that is called when a file changes

(NodeJS)

thank

Closed due to the fact that the question is too common for the user207618, cheops , Denis , aleksandr barakin , HamSter participants on Oct 25 '16 at 18:22 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • The question is not specific, try to reformulate. What does "streaming dates" mean? In my view, this is “sending the correct date and time to the client every second" (maybe with a number of optimization like "throwing the date only when it is changed). What does it mean" a handler who will notify about a file change? "Is that a callback that called when a file changes? - selya
  • You are absolutely right .. that is what I want - beginnergrub
  • corrected the question, it is now more clear - beginnergrub

1 answer 1

About the handler that keeps track of changes - https://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener

Every second, send the date and time to the client:

setInterval(function(){ socket.emit(Date.now()); },1000);