Keys and Secrets
When a Task Node executes tasks, some keys and secrets are injected and made accessible to the task executable by using the process.argv() property. These keys and secrets are command-line arguments that have been passed into the NodeJS Child process.
These keys and secrets include:
// TASK_NAME
// TASK_ID
// EXPRESS_PORT
// NODE_MODE
// MAIN_ACCOUNT_PUBKEY
// SECRET_KEY
// K2_NODE_URL
// SERVICE_URL
// STAKEHow Does This Work?
The NodeJS child_process.fork() method is used to spawn a new Node.js process and a ChildProcess object is returned.
The fork() method accepts the following three arguments:
modulePathβ Astringfor a JavaScript file to execute on the child process (required)argsβ Anarrayofstringto pass as the child process argumentsoptionsβ Anobjectthat you want to pass to the child process
fork("file.js", ["argument"], options);The second argument passed to the fork() method will be accepted by the child process as command-line arguments, which you can retrieve in a Koii Task using the process.argv() property:
If you're using the k2-task-template to create a task, you should see the keys and secrets already retrieved in the init.js file:
Last updated