BlogSharer/fileManager.js

34 lines
711 B
JavaScript
Raw Normal View History

2024-07-06 21:56:39 -05:00
const chokidar = require("chokidar"),
path = require("path"),
fs = require("fs"),
EventEmitter = require("events").EventEmitter
var dataPath = path.join(__dirname, 'data')
var postsPath = path.join(dataPath, 'posts')
var staticPath = path.join(__dirname, 'static')
var reqPaths = [dataPath, postsPath]
for (var i = 0; i < reqPaths.length; i++) {
var p = reqPaths[i]
if (!fs.existsSync(p)) {
fs.mkdirSync(p)
}
}
module.exports = {
data: dataPath,
posts: postsPath,
static: staticPath,
emitter: new EventEmitter()
}
var watcher = chokidar.watch(dataPath)
2024-07-07 22:32:52 -05:00
function emit() {
module.exports.emitter.emit("changed")
}
2024-07-06 21:56:39 -05:00
watcher
2024-07-07 22:32:52 -05:00
.on('change', emit)
.on('add', emit)