Node for Max - Programming Interfaces

The node.script JavaScript API / max-api Module

You can communicate and interact bi-directionally with Max and scripts running in the node.script object using the max-api module. The max-api module contains functions for sending messages to - and receiving messages from - Max.

You can find a complete listing and description of those functions here:

You can also open the API documentation by sending the api message to a node.script object:

Loading the API

When you create a JavaScript file for use with Node for Max, the first thing you’ll do is require “max-api”:

const maxApi = require(“max-api”);

Note: While the max-api module resembles a Node module, you don’t need to send a message like npm install max-api to your node.script object to get things started; when you run a JavaScript file using the node.script object, Max will automatically include the code from the “max-api” module.

Sometimes you want to know if a script is running from within Max, Max for Live, or a Max Standalone application. For this, node.script adds an environment variable called MAX_ENV that you can access as follows:

const MAX_ENV = require("max-api").MAX_ENV;

    if (process.env.MAX_ENV === MAX_ENV.MAX) {
    console.log(“running in Max”);
    } else if (process.env.MAX_ENV === MAX_ENV.MAX_FOR_LIVE) {
    	console.log(“running in Max For Live”);
    } else if (process.env.MAX_ENV === MAX_ENV.STANDALONE) {
    	console.log(“running in a Max Standalone application”)
    } else {
    	console.log(“the program is not running within a node.script”);

You can find simple code examples that demonstrate the functionality of the max-api at

API Functions by category

Here is a list of API functions available:


addHandler Call a function when node.script receives a Max message.
addHandlers Create multiple handlers at once.
removeHandler Remove the handler for a given Max message.
removeHandlers Remove multiple handlers at once. Call with no arguments to remove all handlers.


getDict Retrieve the contents of a named Max dictionary.
setDict Overwrite the entire contents of a named Max dictionary.
updateDict Update the value for a given key in a named Max dictionary.


outlet Send anything out of the leftmost outlet of the node.script object. JavaScript objects will be transformed into Max dictionaries.
outletBang Send a bang out of the leftmost outlet of the node.script object.


post Print a message to the Max console.

See Also

Name Description
Node for Max Documentation - Table of Contents Node for Max Documentation - Table of Contents