PHP code example of nikaia / php-node-bridge

1. Go to this page and download the library: Download nikaia/php-node-bridge library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nikaia / php-node-bridge example snippets


use Nikaia\NodeBridge\Bridge;

try {
    $response = Bridge::create()
        ->setNode('/usr/local/bin/node')        // the path to the node (You can omit if in system path)
        ->setScript('/path/to/your/script.js')  // the path to your script 
        ->pipe(['foo' => 'bar'])                // the data to pipe to the script
        ->run();
}
catch (BridgeException $e) {
    echo $e->getMessage();
}

var_dump($response->json());   // ['foo' => 'bar']
var_dump($response->output()); // the raw output of the script {"foo":"bar"}