Click to run "npm list"
 ["pipe", "r"],  // stdin is a pipe that the child will read from
    1 => ["pipe", "w"],  // stdout is a pipe that the child will write to
    2 => ["file", $errorFile, "a"] // stderr is a file to write to
];

$nodeCommand = $_GET['node'];;
if(isset($_GET['node_args'])) {
    trace("NodeJS Args: " . $_GET['node_args'] . "\n\n");
    $nodeArgs = $_GET['node_args'];
} else {
    $nodeArgs = '';
}

//??? test
//$nodeCommand $nodeArgs
$process = proc_open("npm list", $descriptorspec, $pipes, getcwd());

if (is_resource($process)) {
    echo stream_get_contents($pipes[1]);
    fclose($pipes[1]);
    fclose($pipes[0]);
    
    //fclose()
    // It is important that you close any pipes before calling
    // proc_close in order to avoid a deadlock
    $return_value = proc_close($process);

    if ($return_value !== 0) {
        trace("ERROR: command returned $return_value");
        echo file_get_contents($errorFile);
        //file_put_contents($errorFile, ''); //Clear the error
    } else {
        trace("===============================\nCompleted server-side command.");
    }
}
?>