I have a JavaScript file that I want to run on a remote server. I dont have access to move the script to the server so I want to be able to run the script from my local machine with a remote side argument (filename). Essentially its a script that takes in a file name as an argument and then searches the file that's on the remote server. I tried the following but I get an error code 1. Will i need to write a bash script instead?
ssh name#remote.server 'node filename' < script.js
Here is an image of the script on my local machine and the text on the remote server
I have setup a nodejs server on a machine where I would like to execute scripts. The command is created on the client side and is sent to the nodejs server through a variable. This command contains a bunch of spaces, along with the script and the arguments needed for it to be executed.
An example command to be executed on the machine: <script.sh> -input <inputfile> -output <outputDir> -helper_file <file>
var child = exec('$command')
This command is passed to the server inside a variable. When I try to run the command with the exec process, it stumbles on the spaces and the arguments. How do I get around this issue?
Thanks
I'm trying to create a facebook bot but can not connect to facebook because my node.js command prompt is telling me that "curl" is not recognized as an internal or external command. I have tried to download cURL and have followed the steps in this thread (Curl not recognized as an internal or external command, operable program or batch file) but the error still persists.
Here is a screenshot of the terminal:
Curl Error
cURL is a command line tool. The examples in the documentation are meant to give you a simple command line example for making the HTTP request. In node, you would want to use something like the request or restify module.
I'm running Apache and Node.js on the same server.
I tried to execute this command using PHP:
exec('usr/bin/node', 'var/www/html/app/node/server.js');
var_dump($output);
It returned:
"array(0) {}";
Do you have any idea why PHP did not execute the command node?
Thank you for your help.
Try absolute paths:
exec('/usr/bin/node /var/www/html/app/node/server.js', $output);
usr/bin/node is a relative path meaning it will appended to the current directory php script is executed in.
I have apache and Node.js running on Ubuntu
Is there a way to programatically check if the apache service is running with Node? If it's not running, allow Node.js to start/restart the service, also could the same code be used to run other processes like MySQL?
I'd also like to find a way to make Node execute "ps -u user" and capture the output in a js string or object
I've had a look at Node.js child processes but I can't figure it out
Thanks in advance
You can use the "exec" method of "child_process" module to execute a command from your node app and have its output passed as a parameter to a callback function.
var exec = require("child_process").exec;
exec("ps -u user", function (error, stdout, stderr) {
var myResult = stdout;
//doSomething
});
You could also use shelljs - https://www.npmjs.com/package/shelljs, which has many functions goes directly to shell and is cross-platform. ps command is not one of them, so use exec similar as with child_process.
require('shelljs/global');
exec('ps -aux | grep apache')
With exec you could start/restart service too, however you will need to run node process as root, what's not best option. Or create usergroup specifically for apache.
To run 'ps -u user' use the same. It will return you object with all info you need about processes.
exec('ps -u user');
And than continue with output as you need.
with spawn you can run shell scripts. So if you had a shell script written to check if a processes is running...something like this you should us spawn to run it. something like...
var child = spawn('sh', [__dirname+'/some-status-shell-script.sh'], {env: process.env});
Likewise you can use spawn to access your mysql db...similiar to this