UNPKG

1.45 kBMarkdownView Raw
1# chokidar-socket-emitter
2a 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```
6npm i -D chokidar-socket-emitter
7```
8
9## CLI usage
10
11```
12npm i -g chokidar-socket-emitter
13chokidar-socket-emitter -l 1234
14```
15
16By default listens on port 5776.
17
18## NPM script usage
19Combined 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```
28Start by running:
29```
30npm start
31```
32
33## Programatic usage
34```javascript
35var chokidarEvEmitter = require('chokidar-socket-emitter')
36chokidarEvEmitter({port: 8090}) //path is taken from jspm/directories/baseURL or if that is not set up, '.' is used
37//or specify the path
38chokidarEvEmitter({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
41require('chokidar-socket-emitter')({app: server})
42```
43
44## FAQ
45
46#### Does chokidar have problems with watching drives mounted from VMs hosts/network?
47Yes and if you want it to work, use additional opts property to switch to polling mode
48```
49chokidarEvEmitter({port: 8090, path: '.', chokidar: {usePolling: true}})
50```
51