Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js watchFile

var fs = require('fs');
var filename = process.argv[2];
fs.open(filename, 'r', function(err, fd) {
  if (err) throw new Error('Could not open file');
  var position = 0;
  fs.stat(filename, read);
  fs.watchFile(filename, read.bind(null, null));

  function read(err, stat) {
    var delta = stat.size - position;
    if (delta <= 0) return;

    fs.read(fd, new Buffer(delta), 0, delta, position, function(err, bytes, buffer) {
      console.log("err", err, "delta", delta, "bytes", bytes, "buffer", buffer.toString());
    });
    position = stat.size;
  } 
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: select 2 is not working in nodejs 
Javascript :: bun javascript runtime 
Javascript :: check if a specific user is banned discord js 
Javascript :: Shopify cart context 
Javascript :: angularjs $q all hash 
Javascript :: telerik grid destroy table 
Javascript :: Scale to fit 
Javascript :: moment format time 
Javascript :: JS function examples 
Javascript :: lwc reduceErrors showtoast 
Javascript :: concurrently package usage 
Javascript :: multi command run in one in terminal npm 
Javascript :: Is It Negative Zero (-0)? js 
Javascript :: VM1658:1 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 
Javascript :: starting: intent error type 3 react-native 
Javascript :: increment number in for loop javascript 
Javascript :: añadir input file a formdata javascript 
Javascript :: javascript to typescript converter 
Javascript :: number of filters 
Javascript :: using Canvas with tkinger draw arc 
Javascript :: how to check my javascript code 
Javascript :: pass a callback funcion into an async function node js 
Javascript :: terraform for loop json 
Javascript :: create index with multiple fields mongo 
Javascript :: Javascript shows me TypeError saying my variable is undefined 
Javascript :: angular create spec file for existing component 
Javascript :: Angular js Directive to Fire "click" event on pressing enter key on ANY element 
Javascript :: Conditional navigation inside Tabs 
Javascript :: RegEx Pattern Validations failing on html input 
Javascript :: sending api with limited fields in express 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =