JavaScript Answers

How to execute PHP scripts within Node.js web server?

Spread the love

To execute PHP scripts within Node.js web server, we call the exec function.

For instance, we write

const exec = require("child_process").exec;

app.get("/", (req, res) => {
  exec("php index.php", (error, stdout, stderr) => {

to call exec to run index.php with php.

We get the output from the stdout parameter in the callback.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.