Vamshi
Vamshi

Reputation: 349

How to run node module in php and display output?

I have a use case where i need to run a node module in php script and display it's output back on the page. Here's the steps I followed:

  1. I have installed the module npm install -g md2gslides
  2. I am using PHP's exec() for running the module
    exec('node_modules/md2gslides/bin//md2gslides.js --version 2>&1', $output);
    But it's not working. The error is below: enter image description here

However, it runs in ubuntu's terminal without issues. enter image description here

What is wrong here?

Upvotes: 0

Views: 566

Answers (1)

Vamshi
Vamshi

Reputation: 349

The error not because of php but because of the path.join() in line 33 of md2gslides.js
const STORED_CREDENTIALS_PATH = path.join(USER_HOME, '.md2googleslides', 'credentials.json');

It tries to find the credentials.json in users home directory. But I think it's unable to.

So I moved the file to node_modules/md2gslides/bin and modified path.join() as
path.join(__dirname, '.md2googleslides', 'credentials.json')

This solved the issue.

Upvotes: 1

Related Questions