Skip to content
Advertisement

Executing nodejs script file in PHP using exec()

In my Application, I want to execute a Node.JS file from PHP which in turn makes a http request to another PHP file.

In short this is the Process that I am doing.

PHP file—>calls–> Nodejs file—>processes data –>and makes http request to–>PHP File

When I run the nodejs file via terminal, it successfully makes the http request to another PHP file and I get what I want.

But, when I try to run the nodejs file through PHP, the nodejs files is not able to find some modules.

My code in PHP:

JavaScript

This is the error that I am getting:

JavaScript

Advertisement

Answer

I got it finally. Its just ignorng the NODE_PATH variable for reasons unkown 🙁

In the Nodejs File I hade to give the absolute path of the module like this:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement