Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- const fs = require('fs');
- // Declare needed variables
- const filename = 'most_recent_follower.txt';
- const filelocation = 'F:/Web/nodejs/naivebot/server/data/streamlabels/';
- const filePath = filelocation + filename;
- const changedFiles = {};
- // watch file for changes
- fs.watchFile(filePath, { encoding: 'utf8' }, (cur, prev) => {
- // read file content for comparison
- const fileInfo = fs.readFileSync(filePath, 'utf8').trim();
- // make file change comparison
- // check existing object info (changedFiles[filename])
- // and compare it to the new data (fileInfo)
- const fileChanged = changedFiles[filename] !== fileInfo;
- // if changes we have a new event not a repeat
- if (fileChanged === true) {
- // send message to chat here
- console.log('Send message to chat here');
- }
- // assign file content to the object for future reference
- changedFiles[filename] = fileInfo;
- });
Add Comment
Please, Sign In to add comment