docs: custom-modul: file read example

This commit is contained in:
bordun 2020-12-17 15:02:45 +01:00
parent 3a1e458d8c
commit 34197dd38a

View file

@ -236,3 +236,41 @@ module.exports = {
}
```
## Read file
```js
var fs = nativeRequire('fs')
module.exports = {
oscOutFilter:function(data){
// Filter outgoing osc messages
var {address, args, host, port} = data
if (address === '/file') {
fs.readFile(args[0].value, 'utf8' , (err, data) => {
if (err) {
console.error(err)
return
}
receive('/html', data)
})
return // bypass original message
}
// return data if you want the message to be processed
return {address, args, host, port}
}
}
```