Debugging Max JS Patches... node.js?

Quick question to the 3l33t h4x0rs out there. How are you debugging your Max javascript bits? Anyone using node.js? I spend a lot of time bouncing back and forth between my Max window and my JS editor. For things largely algorithmic it’d be much nicer to have the whole flow outside Max. To that end, I’ve been thinking about a little node.js shim but am curious if anyone has done anything similar.

(Note, I’ve scanned the node.js grid study which is awesome but my question is not so much about grid connectivity and rather about debugging workflow; that said, if you’re using node.js for anything grid-related, I’d be curious!)

Thanks in advance!

This is not possible. Even though both use the same scripting language (JS), it is interpreted within and for their (isolated) environments. The cannot talk to each other.

I’m terrible at explaining sorry. And I’m not even a heavy Max user… But I guess you’re limited to debugging with post().

edit: I may have totally misunderstood your question :sweat_smile:

1 Like

i assume you are using JavaScript for i/o and Max for DSP. Occurs to me that because of this separation of concerns you really should be able to do all of your JS programming entirely outside of Max, and then use OSC over UDP to communicate between.

I see a couple of OSC libraries in NPM.

I’d love to hear more about your preferred JavaScript tooling, especially for debugging.

unsure on debugging within max/msp, but visual studio code has a really great integrated debugger if you go the node.js route!


Yeah, I had node.js in mind. Been a dog’s age since I’ve tried VS, I’ll have to give it a whirl.

1 Like

I was going to say, this:

vscode is pretty amazing all around. (Just be sure to set autowatch equal to 1! :wink:)

Sorry, yeah, I was very unclear. Actually, at the moment, I’m writing a bit of code to do some arc animations (spinners, wedges, wheels, etc.) and most of this is just playing with math and arrays of ints. The code I’m looking at does no I/O (besides posting to the Max console and outlets). In another world, I’d probably even write tests.

This is spot on. What I’m really looking to do is explore interpreting algorithmic JS in a node context so I can get debugging. I know it’s possible (and actually just quickly hacked something together) and now I’m just curious if anyone else is doing something similar.

Thanks for all the responses!

To be more concrete, here’s what I did:

  1. defined app.js (bad name but I was following this short vscode node debugging tutorial)
// the "module" that contains the bits I want to test drive 
var max = require('./max');

// the function I want to test
  1. added a module declaration to my max JS file (called imaginatively max.js) that exports the functions I want to reach (in this case just bang).
// ...

module.exports = {
  bang: bang

function bang() {
    console.log("bang!"); //<= breakpoint reached here :) 
    outlet(0, buffer); //<=this barfs of course
    // ...

// ...

The amazing thing is that debugging actually works.

To make it even better, I’ll probably add an outlet function (conditionally if it’s not defined) that does the right thing outside Max (probably just dumps to the console) and similarly redirect post to console.log. Fun stuff!

EDIT: for those reading along, a node-friendly way of conditional function declaration looks as follows (!outlet ain’t enough).

if (typeof outlet == 'undefined' || !outlet ) {
    outlet = function (index, message) {
        console.log("Outlet [" + index + "]:" +  message);
1 Like

i’ve got a few modules you might be interested in (sorry if you’re already aware):

^^ includes arc and grid support

this project kind of brings it all together:

sort of like pages, but without any UI and more configurable. you can instantiate scripts (step sequencer, midi note recorder/looper, etc) with various config parameters on various devices. it has application paging and pattern recorders as well.

this is a really smart idea!! just stub out the max calls you use, write unit tests and debug using node. brilliant!


i’ve got a few modules you might be interested in (sorry if you’re already aware)

Only barely. Awesome. Thanks![quote=“phortran, post:9, topic:4666”]

this is a really smart idea!! just stub out the max calls you use, write unit tests and debug using node. brilliant!


Thanks in part to your vote of confidence I threw my quick ideas into a repo on github here:

It’s all pretty thin but in a way that’s kind of the beauty of it. Needless to say, input is most welcome. I’m in fairly new territory here so I’ve got a lot to learn…

Cheers and thanks again for the encouragement! :beers:

1 Like