Some questions about node.script and Max 8

    Oct 11 2018 | 7:20 pm
    I currently (Max 7) use mxj net.udp to communicate with an external Python script. In Max 8 would the new node.script have the same plussides/downsides as this method? e.g. the script runs in true parallel as a separate process; but using UDP incurs some amount of latency.
    Can node.script refer directly to things like colls and dicts? The NPM libraries wouldn't happen to also be available in the regular js object, would they?

    • Oct 11 2018 | 9:23 pm
      Hey there, lots to cover here but I'll try to sum up as best I can.
      Yes, node for max runs a node script in a separate process. Communication with the process happens over a socket, so there is some non zero latency. Whether that latency matters depends on your application. Each node.script object owns its own node process, so you'll have as many processes as you have node.script objects.
      There are some advantages to node for max. First, the node processes are true child processes of the main Max process, so you don't have to close those processes manually if you want them to go away when Max quits. Second, there's some attempt to convert types between JavaScript and Max types. If you send a dictionary to Node from Max, it will be converted into a JavaScript object (and visa versa).
      There is support for reading/writing to named Max dictionaries from Node, but not coll objects.
      Finally, you can use require and include in the plain JS object. However, these word differently from the Node equivalent. Check the reference docs for more info.
    • Oct 11 2018 | 10:27 pm
      Thanks, very informative! Has that always been the case with the plain JS? I really need to look deeper into that object.
      I've heard that node.script can easily create files and folders. Can it delete files and folders just the same?
    • Oct 11 2018 | 10:46 pm
      As far as I know (admittedly I haven't been too close to it) this has been the case with JS for a while, though maybe not forever.
      As far as what Node can do, here's the api docs for the version of node that ships with Node for Max.
      Node can absolutely create and delete files. It can navigate up and down the operating system folder hierarchy, enumerate files, spawn processes--basically anything an application can do. If you look in Extras -> n4m-launcher, there's a button to launch an example that shows how to interact with the file system.
      good luck and have fun!
    • Oct 11 2018 | 11:11 pm
      just quickly mentioning that js require is/has been available since Max 7. you can find more info here: