Ws-Filewatcher is a cli that will watch for file change and open a websocket server where it will send a message everytime the file is updated
npm install ws-filewatcherWs-Filewatcher is a cli that will watch for file change and open a websocket server where it will send a message everytime the file is updated
- Npm or Yarn, the package managers for NodeJs
Here are the instruction to install the cli globally, but you can do it locally on your projects.
``bash`
npm i -g ws-filewatcher
OR
yarn global add ws-filewatcher
Here is the minimum you need to write to launch the service:
`bash`
ws-filewatcher -f path/to/my/file
:warning: 'path/to/my/file' isn't necessarily an existing file. You may want to listen for a file creation. So if you make a typo in the path, it won't be considered as an error
| | Verbose |
| ------------- | --------------- |
| parameter | --verbose |-v
| shortcut | |false
| default value | _(bool)_ |
| description | Allow loggings |
| | Port |
| ------------- | ------------------------------------ |
| parameter | --port |-p
| shortcut | |9999
| default value | _(number)_ |
| description | Set the port of the WebSocket server |
| | Command |
| ------------- | -------------------------------------------- |
| parameter | --command |-c
| shortcut | |""
| default value | _(string)_ |
| description | The command will be run on every file update |
`bash`
ws-filewatcher -f path/to/my/file -p 8080 -v -c 'cp folder/file other/folder/file'
_The example assume you are running the code inside a browser_
`javascript
const ws = new WebSocket('ws://localhost:9999')
ws.onmessage = () => {
console.log('My file was updated!')
}
``