Executing nodejs script file in PHP using exec()
<p>In my Application, I want to execute a Node.JS file from PHP which in turn makes an HTTP request to another PHP file.</p>
<p>In short this is the Process that I am doing.</p>
<p><strong>PHP file---&gt;calls--&gt; Nodejs file---&gt;processes data --&gt;and makes http request to--&gt;PHP File</strong></p>
<p>When I run the nodejs file via terminal, it successfully makes the http request to another PHP file and I get what I want.</p>
<p>But, when I try to run the nodejs file through PHP, the nodejs files is not able to find some modules.</p>
<p>My code in PHP:</p>
<pre><code>$nodeJsPath = '/var/www/html/projectfolder/js/nodefunc.js';

$ret = exec(&quot;node &quot;.$nodeJsPath.' 2&gt;&amp;1', $out, $err);
</code></pre>
<p>This is the error that I am getting:</p>
<pre><code>Array
(
    [0] =&gt; module.js:457
    [1] =&gt;     throw err;
    [2] =&gt;     ^
    [3] =&gt; 
    [4] =&gt; Error: Cannot find module 'some_module'
    [5] =&gt;     at Function.Module._resolveFilename (module.js:455:15)
    [6] =&gt;     at Function.Module._load (module.js:403:25)
    [7] =&gt;     at Module.require (module.js:483:17)
    [8] =&gt;     at require (internal/module.js:20:19)
    [9] =&gt;     at Object.&lt;anonymous&gt; (/var/www/html/projectfolder/js/nodefunc.js:5:9)
    [10] =&gt;     at Module._compile (module.js:556:32)
    [11] =&gt;     at Object.Module._extensions..js (module.js:565:10)
    [12] =&gt;     at Module.load (module.js:473:32)
    [13] =&gt;     at tryModuleLoad (module.js:432:12)
    [14] =&gt;     at Function.Module._load (module.js:424:3)
)
</code></pre>