Node JS 14.16.1
    • 10 Sep 2024
    • 1 Minute to read

    Node JS 14.16.1


    Article summary

    Skillable Studio allows execution of scripts against a cloud subscription, as well as executing scripts that do not have a target. Scripts are used in Automated Activities and Life Cycle Actions.

    This script execution environment is running Node.js 14.16.1.

    Interacting with Skillable Studio

    Your scripts can communicate success or failure to Skillable Studio in one of two ways.

    Return a Boolean value

    //do stuff... all good
    return true;
    
    //do stuff... uh oh
    return false;
    

    Use setActivityResult

    //do stuff... all good
    setActivityResult(true);
    
    //do stuff... uh oh
    setActivityResult(false);
    

    You can also report the result as a score %...

    //do stuff... we want to report success and set the score value as 50%
    setActivityResult(0.5);
    

    Send a Notification to the User

    Notifications appear as real-time toast notification in the lab client.

    sendLabNotification("A notification from Node.js!");
    

    Lab Variables

    Lab variables are always string name/value pairs. Variable values are scoped to the lab instances and become available within the lab instructions as well as subsequent script executions.

    setLabVariable("myVariable1", "This was set by Node.js in the cloud!");
    

    You can "receive" a variable in your script...

    #a variable set elsewhere in the lab, but we can use it in our script
    const myVariable1 = "@lab.Variable(myVariable1)";
    

    ##Dealing with Async

    It's very common to work with asynchronous JavaScript.

    Use setActivityResult

    If you choose to use setActivityResult, the last time it is called within your script will determine the outcome.

    setTimeout(function() {
        console.log("This message was left inside the async code.");
        setActivityResult(true);
    }, 1000);
    return false; //<- this will have no effect, as it will be evaluated before the async code is run.
    

    Use a Promise

    You can use a promise and return the result to Skillable Studio by resolving the promise.

    return await (new Promise((resolve, reject) => {
        setTimeout(function() {
            console.log("This message was left inside the async code.");
            resolve(true);
        }, 1000);
    }));
    


    Was this article helpful?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.