0

so I've been trying to run an SMS script after the user submits a form. If I use

node send-sms.js 

locally on my machine, it works. However, if I try to use

$sendSmsPath = "send-sms.js";
exec('/public_html/node_modules/node '.$sendSmsPath);

Nothing happens. No error, nothing. I tried using a relative path, as well as an absolute one. My folder scheme is as follows: public > other_folder > php > php_file.php AND public > node_modules

Any ideas are welcome, thanks

2
  • Run the command which node and tell me the output? Commented Mar 5, 2019 at 20:27
  • 1
    Thanks for the quick reply. If I run it on my machine, it returns "/c/Program Files/nodejs/node" Commented Mar 5, 2019 at 20:30

2 Answers 2

2

You are using the wrong path to Node.js. Try this:

<?php
$sendSmsPath = "send-sms.js";
exec('/c/Program Files/nodejs/node '.$sendSmsPath);

node_modules is for the dependencies of your script, not the actual Node.js executable.

If you'd like to run your script on another machine make sure it has Node.js installed globally and you know the path of the executable (can be found with which node)

Sign up to request clarification or add additional context in comments.

2 Comments

Well, yes, but I need it on the public host. So that path is not good for me. Can I install node to my workspace folder?
@ToniFlorea You would have to talk with your hosting provider.
0

return or print your values in your js file so you will get these variabales in your output

$output = shell_exec('node C:\xampp\htdocs\noah-imports\app\NodeJs\index.js');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.