External file in custom-module

#1

Hi. Let’s say I have 1000 tracks in my DAW. Is it possible to define an object (e.g. a ‘tracks’ object) in a separate file, and import that into the custom module?

#2

You can’t do that at run time for security reasons, but you could manage your sources in multiple files and bundle them into one custom module file before loading it in o-s-c.

The common pattern for this is using the browserify library:

  1. manage your tracks in tracks.js
module.exports = {
    // tracks definition
}
  1. load them in your main module file (we’ll call it main.js):
var tracks = require('./tracks.js')

module.exports = {
    oscInFilter: function(data){
        // etc
    }
}
  1. bundle your sources as custom-module.js :
    browserify main.js -o custom-module.js --standalone module.exports
#3

Thanks for your reply. Bare with me here. So I installed node, then ran npm, then installed browserify. I created my two files (main.js and tracks.js) and then ran
browserify main.js -o custom-module.js --standalone module.exports

I got this back:

C:\Users\Luke\Desktop\node-v10.15.3-win-x64>browserify main.js -o custom-module.
js --standalone module.exports
Error: Parsing file C:\Users\Luke\Desktop\node-v10.15.3-win-x64\main.js: Unexpec
ted token (14:0)
    at Deps.parseDeps (C:\Users\Luke\Desktop\node-v10.15.3-win-x64\node_modules\
browserify\node_modules\module-deps\index.js:510:15)
    at getDeps (C:\Users\Luke\Desktop\node-v10.15.3-win-x64\node_modules\browser
ify\node_modules\module-deps\index.js:438:44)
    at C:\Users\Luke\Desktop\node-v10.15.3-win-x64\node_modules\browserify\node_
modules\module-deps\index.js:421:38
    at ConcatStream.<anonymous> (C:\Users\Luke\Desktop\node-v10.15.3-win-x64\nod
e_modules\browserify\node_modules\concat-stream\index.js:37:43)
    at ConcatStream.emit (events.js:194:15)
    at finishMaybe (C:\Users\Luke\Desktop\node-v10.15.3-win-x64\node_modules\bro
wserify\node_modules\readable-stream\lib\_stream_writable.js:630:14)
    at endWritable (C:\Users\Luke\Desktop\node-v10.15.3-win-x64\node_modules\bro
wserify\node_modules\readable-stream\lib\_stream_writable.js:638:3)
    at ConcatStream.Writable.end (C:\Users\Luke\Desktop\node-v10.15.3-win-x64\no
de_modules\browserify\node_modules\readable-stream\lib\_stream_writable.js:594:4
1)
    at DuplexWrapper.onend (C:\Users\Luke\Desktop\node-v10.15.3-win-x64\node_mod
ules\browserify\node_modules\readable-stream\lib\_stream_readable.js:577:10)
    at Object.onceWrapper (events.js:277:13)
#4

Error: Parsing file C:\Users\Luke\Desktop\node-v10.15.3-win-x64\main.js: Unexpected token (14:0)

This means there is something wrong in main.js at line 14

#5

My bad. I set up my definitions inside the module.exports!

#6

You can see it this way: require('./file.js') returns the variable assigned to module.exports in file.js.