-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtcpServer.js
36 lines (28 loc) · 995 Bytes
/
tcpServer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
let chokidar = require('chokidar')
let net = require('net')
let jsonSocket = require('json-socket')
let tcpServer = net.createServer();
tcpServer.listen(8001);
tcpServer.on('connection', function(socket) {
socket = new jsonSocket(socket);
fswatch(socket);
});
function fswatch(socket){
let resObj = {}
let watcher = chokidar.watch('.', {
ignored: /[\/\\]\./,
persistent: true
});
watcher
.on('add', function(path) { console.log('File', path, 'has been added'); })
.on('addDir', function(path) { console.log('Directory', path, 'has been added'); })
.on('change', function(path) {
resObj.action = "write"
resObj.path = path
resObj.type = "file"
socket.sendEndMessage(resObj);
})
.on('unlink', function(path) { console.log('File', path, 'has been removed'); })
.on('unlinkDir', function(path) { console.log('Directory', path, 'has been removed'); })
.on('ready', function() { console.log('Initial scan complete. Ready for changes.'); })
}