External file in custom-module

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?

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

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\
    at getDeps (C:\Users\Luke\Desktop\node-v10.15.3-win-x64\node_modules\browser
    at C:\Users\Luke\Desktop\node-v10.15.3-win-x64\node_modules\browserify\node_
    at ConcatStream.<anonymous> (C:\Users\Luke\Desktop\node-v10.15.3-win-x64\nod
    at ConcatStream.emit (events.js:194:15)
    at finishMaybe (C:\Users\Luke\Desktop\node-v10.15.3-win-x64\node_modules\bro
    at endWritable (C:\Users\Luke\Desktop\node-v10.15.3-win-x64\node_modules\bro
    at ConcatStream.Writable.end (C:\Users\Luke\Desktop\node-v10.15.3-win-x64\no
    at DuplexWrapper.onend (C:\Users\Luke\Desktop\node-v10.15.3-win-x64\node_mod
    at Object.onceWrapper (events.js:277:13)

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

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

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

In v0.47.0 it is possible to read/write external json files from the custom module.

That’s cool! So what would this look like in my custom module if I have an external file tracks.js?

You’d have to name it tracks.json (loading javascript modules dynamically is still not allowed) and use the javascript object notation in it to define your data (see https://json.org/).
For example:


  "track_1": {
      "name": "bass",
      "volume": 0


var tracks = loadJSON('./tracks.json')

module.exports = {
  // etc