Starting and stopping a process, @watch and @autostart
Starting a Node process with Arguments
Each node.script object manages a single Node process, which runs alongside the Max application. You start a Node process by sending the message to a node.script object and stop the process by sending the message .
There are times when you want to pass arguments to the Node process as it starts. For example, you might be working with a web-server script that displays different content depending on one of several configuration files it loads. Here, you might want to pass the name of the configuration file as an argument to.
To pass arguments to the Node process on startup, append those arguments to themessage. For example, the message would pass the string "config1.json" to the Node script as it starts.
Any arguments sent to the Node process will be available in the global variable. The first two arguments will always be:
- The path to the Node executable
Any arguments beyond those two will be the ones that you passed to the Node script.
For more information on the global variable process.argv see https://nodejs.org/docs/latest/api/process.html#process_process_argv
The @autostart, @watch and @args attributes
Similarly, you can use the node.script object to start the Node script automatically when the patch is opened.attribute of the
Keep in mind that using either of these attributes never sends node.script object, so you cannot send startup arguments to the node.script object in the usual way. Instead, the attribute can be used to send arguments to the Node script, which will be accessible via process.argv.to the
// Slice process.argv in order to get the actual arguments because // in NodeJS the first two values have the following content: // // process.argv - is the path of the Node executable used // process.argv - is the path of the JS program that is executed const args = process.argv.slice(2)
For more information on process.argv see the Node JS API Documentation: https://nodejs.org/dist/latest-v10.x/docs/api/process.html#process_process_argv
Note: Any arguments that you express using theattribute will only be available in conjunction with the or attributes. Otherwise, arguments that follow a message will override the arguments specified with .
|Node For Max Documentation - Table of Contents||Node For Max Documentation - Table of Contents|
|Node For Max - Script Lifecycle||Node For Max - Script Lifecycle|