1 | # chokidar-socket-emitter
|
2 | a simple chokidar watcher and socket.io server which emits file system events to all connected socket.io clients. Primarily it should serve as an event source for **[systemjs-hot-reloader](https://github.com/capaj/systemjs-hot-reloader)** but you can use it any other way.
|
3 |
|
4 | ## Install
|
5 | ```
|
6 | npm i -D chokidar-socket-emitter
|
7 | ```
|
8 |
|
9 | ## CLI usage
|
10 |
|
11 | ```
|
12 | npm i -g chokidar-socket-emitter
|
13 | chokidar-socket-emitter -l 1234
|
14 | ```
|
15 |
|
16 | By default listens on port 5776.
|
17 |
|
18 | ## NPM script usage
|
19 | Combined with [browser-sync](https://browsersync.io/):
|
20 |
|
21 | ``` json
|
22 | "scripts": {
|
23 | "start": "npm run serve & npm run watch",
|
24 | "serve": "browser-sync start --server",
|
25 | "watch": "chokidar-socket-emitter"
|
26 | },
|
27 | ```
|
28 | Start by running:
|
29 | ```
|
30 | npm start
|
31 | ```
|
32 |
|
33 | ## Programatic usage
|
34 | ```javascript
|
35 | var chokidarEvEmitter = require('chokidar-socket-emitter')
|
36 | chokidarEvEmitter({port: 8090}) //path is taken from jspm/directories/baseURL or if that is not set up, '.' is used
|
37 | //or specify the path
|
38 | chokidarEvEmitter({port: 8090, path: '.'})
|
39 |
|
40 | //you can also supply an http server instance, that way it will run within your server, no need for extra port
|
41 | require('chokidar-socket-emitter')({app: server})
|
42 | ```
|
43 |
|
44 | ## FAQ
|
45 |
|
46 | #### Does chokidar have problems with watching drives mounted from VMs hosts/network?
|
47 | Yes and if you want it to work, use additional opts property to switch to polling mode
|
48 | ```
|
49 | chokidarEvEmitter({port: 8090, path: '.', chokidar: {usePolling: true}})
|
50 | ```
|
51 |
|