Node for Max - Javascript Differences

The js object and the node.script object


Max offers you two ways to run JavaScript programs in the context of working with Max: the js object and the node.script object. This section of the guide will explain some of the key differences between the two Max externals - how they work, their advantages and limitations, and which tool is best for a given situation.

The Max js external object provides an embedded version of the Spidermonkey JavaScript engine. It provides full access to the Max’s Javascript API, the Live API , and patcher scripting capabilities ).

The Max node.script external object provides you with a way to run Node programs alongside your Max patch, enables bi-directional communication with your Max patch, and gives you full access to the Node JS API ( ), and npm packages. You can think of the node.script object as providing one or more JavaScript-based programs that run alongside your Max patch and work with it.

Choosing the Right Tool - When Should You Use node.script and/or js?

Both, the js and node.script external objects have their distinct cases. They may even be used together in a single Max patcher, in some circumstances. Here are some circumstances in which using node.script is a good choice:

  • You want your Max patch to communicate with a web resource, but you don't want the performance of your patch to be affected by network requests. Maybe you're writing a Node web server that lets you update your patch from a remote device. Rather than use the full integration of Max and JavaScript—which could affect the performance of your patch— it would be more efficient to use a separate Node JS program, running as a separate “service” alongside your patch.
  • Using node.script is the better choice in situations where you want to interact with other command line utilities, the file system, or to start up and communicate with a database to manage data for your patch.
  • With the node.script, object you have full access to everything that npm provides.
  • You can use the remote debugger in conjunction with the node.script object, which will allow you to set breakpoints and inspect local variables.

However there are situations where the js object is the more appropriate tool:

  • You should use js when you are attempting to manipulate the Max patcher directly via Patcher Scripting (such as adding and removing objects and connections dynamically).
  • The js object gives you direct access to a Max-specific API that allows you interact with parts of Max like the Jitter API, the Live API and other Max specific features.
  • For functionality that does not require a separate process, the js object might be the more appropriate choice. It behaves more like a standard Max object with functionality and logic defined in JavaScript, and it doesn't add the complexity of managing another process as with node.script.

See Also

Name Description
Node for Max Documentation - Table of Contents Node for Max Documentation - Table of Contents
js Execute Javascript