mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
NoLog file watching
This commit is contained in:
@@ -6,7 +6,8 @@ module.exports = {
|
||||
Beep: Beep,
|
||||
WriteBackup: WriteBackup,
|
||||
FileExists: FileExists,
|
||||
CreatePath: CreatePath
|
||||
CreatePath: CreatePath,
|
||||
WatchFile: WatchFile
|
||||
}
|
||||
|
||||
var fs = require('fs')
|
||||
@@ -24,6 +25,25 @@ function FileExists (path) {
|
||||
return fs.existsSync(path)
|
||||
}
|
||||
|
||||
function WatchFile (file, callback) {
|
||||
if (FileExists(file)) {
|
||||
fs.watchFile(file, (curr, prev) => {
|
||||
fs.readFile(file, 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
// console.log(err)
|
||||
} else {
|
||||
callback(data)
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
console.log(file + ' does not eadjsalék')
|
||||
setTimeout(() => {
|
||||
WatchFile(file)
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
|
||||
function CreatePath (path, onlyPath) {
|
||||
if (FileExists(path)) { return }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user