From 34197dd38af651b140cd104377a434b0ffeb8599 Mon Sep 17 00:00:00 2001 From: bordun Date: Thu, 17 Dec 2020 15:02:45 +0100 Subject: [PATCH] docs: custom-modul: file read example --- resources/docs/docs/custom-module/examples.md | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/resources/docs/docs/custom-module/examples.md b/resources/docs/docs/custom-module/examples.md index dfd3908f..84704694 100644 --- a/resources/docs/docs/custom-module/examples.md +++ b/resources/docs/docs/custom-module/examples.md @@ -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} + + } + + +} +```