Max 8 Yay! - Now I need help with Node
Hey all,
Like many, I am very excited with the release of Max 8. A lot of the new features seem to improve the workflow, among them being node. Truth is, I'm a noob with node and I desperately want to pull NASA API data.
The following npm resource seems to be the best out there for pulling data from NASA's API: https://www.npmjs.com/package/nasa-sdk/v/1.1.10
So, if anyone can help me get started - I cannot even seem to find the .json file to download :|
any help would be appreciated. Ideally, I'd be able to build a patch that pulls data from Near Earth Objects (there is a script for this in the readme - I just don't know how to "get it in Max")
Thanks in advance!
Best,
T
One good first place to look might be the examples available here:
https://github.com/Cycling74/n4m-examples
Yeah, I checked there, along with the help and reference files and it still seems way too foreign to me as far as getting started - thanks for the link though!
Any other help is greatly appreciated :]
Hi Santino,
It sounds like the thing to do is to use NPM to create a Node package that depends on the NASA API module. Then, import that into the Node script you run from Max. I hate to self-plug, but I just made a how-to video that does something very similar, using the Tonal NPM package. It might be a helpful starting point for you.
Good luck!
Sam,
Thank you for the input - self plug all the way! Your videos have always been endlessly helpful and fun. I'm gonna give this a shot later today and see what I come up with - thanks comrade, much appreciated!
- Tino
Wowza!
Little did I know what I would be getting into. Great tutorial by the way, super helpful! I managed to get somewhere by following that, however In the case of the flying space objects, I have had slow progress.
Essentially, I've managed to get the nasa-sdk installed properly in a folder with my max patch and I have this running alongside vis studio. Since all this java nonsense is new to me, I am chugging along at a snails pace. As far as initiating communication between the nasa-sdk and max - I'll be using node.script and the code from npm - right?
Yes, I know this is ultra amateur hour comin from me over here, but I desperately want to understand how to make these puppies communicate - any other help is greatly appreciated! Thanks!
- T

Hey hey,
I admire your courage. Okay so, your high level understanding of how the parts all fit together is 100% correct. Just a few tweaks to help you get unstuck:
It's JavaScript, not Java. No, they have nothing really to do with each other. Yes, it's confusing.
Digging into this import thing a bit, I learned something myself. Node 8 LTS (which is the version of Node that Max uses) is current with JavaScript ES6, with one difference: no import. So the tl;dr here is that you should use require instead of import. so:
const { NEO } = require("nasa-sdk");
3. I don't really understand what's happening on line 11. Are you copying from some example?
Gracias sensei,
I appreciate your guidance! Alright, this is all great info and I'm glad I'm not a total dunce. Aha, that would make sense! I keep getting the error that there is no "import" command, this is good news.
However, as far as far as line 11, I may be typing gibberish but I am essentially trying to use the framework from your example with the JavaScript examples posted for the NASA API here on npm: https://www.npmjs.com/package/nasa-sdk/v/1.1.10#neo-feed
I may be totally off but I will find a way to get this info in a usable way in Max - I truly appreciate your input!
Gotcha. Two things then: first, that call is asynchronous, so you have to use a promise and second, the result is going to be JSON that you want to parse. For example:
maxApi.addHandler("fetchFeed", () => {
NEO.feed().then((result) => {
const data = JSON.parse(result);
maxApi.outlet(data.near_earth_objects)
})
})
might be a place to start. By the way, if you're looking for a really solid, beginner's introduction to JavaScript, I highly recommend Coding Train at https://www.youtube.com/user/shiffman
Awesome, thank you for the references. I'm definitely going to try and make time for that channel.
I was totally in the dark this morn and your help got me somewhere, though I'm not sure where or what is being printed... I still sense progress. I'll find a way to get this info into a usable and beautiful piece of art - somehow.
Anyway, thanks again for your help thus far, I'm looking forward to taking this further. Hasta for now - and if anyone else has input please feel free to offer, I'm all ears!

Does anyone know if it's possible to build standalones with the node packages bundled? I tried to export the 'tonal chord builder' example, but the standalone couldn't locate the .js file of the node.script object. (I included the whole folder with when exporting to .app).
Hmm, I'll have to do a bit of digging here, as I'm not totally sure what you need to do in order for Node for Max to work with standalones. It might be possible, but I need to do a bit of research. Either way, making the process easier and more consistent is something we're actively working on, thanks!
Is there any reason (aside from a file not being in the correct directory) that node.script will spit out a "Unable to launch process." error message once "script start" has been clicked?
Usually a syntax error. Try attaching a node.debug object to the rightmost outlet.
Alright, the error reads:
Error: Control client connection timed out.
at Timeout.setTimeout [as _onTimeout]
(/Applications/Max.app/Contents/Resources/C74/packages/Node For Max/source/lib/nsProcessShell.js:245:19)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290.5)
Oh interesting, that might be something else. You mind sharing your patch + script?
sure thing, but you'll probably be a bit underwhelmed to find it’s just following along with your tutorial, lmao.
https://drive.google.com/open?id=12Ui9Wm76ZW2QHvFgubH4DoDTglQBdGqc
I'm not underwhelmed but I am confused—this works fine for me. So looking at this patch I see [prepend detect] connected to (script start), which means that you're restarting the script every time you hit a note. It could be that restarting the script this often is causing a problem. That shouldn't happen, but it might explain things.
If you connect [prepend detect] to node.script directly, do you still see this error? Also, try connecting the output of node.script to the rightmost inlet of the message box, not the leftmost, so you can actually see the output of node.script.
1. Bypassing script start does indeed fix the timeout error.
2. Ah, yes. That is indeed a helpful (as per usual) suggestion. (I was too focused on the debug/ console errors ><)
3. As always, I very much appreciate the (willingness to) assist. -nods w/ fervor-
Unless I'm distracted by Agadmator videos I'm always happy to help. Actually I'm really glad you asked about it, because while it's not crashing or anything I'd consider it a usability bug. What I believe is happening here, is that you're sending two (script start) messages, one after the other. The second one succeeds, but the first one fails because it times out (makes sense kind of, since it's basically been abandoned). But the error message from the first attempt prints after the success message from the second one, which makes it look like something's gone wrong when actually it hasn't.
Anyway!! Something for me to improve for the next version of node.script. Thanks!
lmfao. I look forward to your n4m video where you take move lists from historic chess matches as a starting point for algorithmic compositions. (Additionally, you should check out snooker -- that's a pretty intense one as well. ><)
Ah, that actually does make sense. Yeah, I can't exactly explain what the reasoning behind my routing that the way it was (probably some misguided desire for cleanliness), but I look forward to the days where that's no longer of concern. ;)
Seriously, thanks again. -nod-