Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to run a shell command #10

Closed
concatime opened this issue Apr 21, 2018 · 6 comments
Closed

Possibility to run a shell command #10

concatime opened this issue Apr 21, 2018 · 6 comments

Comments

@concatime
Copy link

concatime commented Apr 21, 2018

Hi. It would be really useful if we were able to execute a shell command and return the output. I don't think it's possible right now, not at my knowledge at least.
Thank you.

@maximkonovalov
Copy link

Hello,

could you please clarify what do you mean? An example will be perfect.

Thanks,

Maxim

@concatime
Copy link
Author

For example, something like this:

function ssl_vers(req, res) {
  return os.exec("/usr/local/bin/openssl version");
}

and

js_include http.js;
js_set $ssl_vers ssl_vers;
server {
    listen 8000;
    location /ssl_vers {
        return 200 $ssl_vers;
    }
}

@maximkonovalov
Copy link

Issam,

Thanks for clarification. Unfortunately I must confirm that this is no-go simple because njs is intended to be a supplementary tool for njs code development that runs inside nginx. And nginx won't be able to run external programs for any foreseeable future.

@concatime
Copy link
Author

Well, thank you for having at least considered my request. I totally understand your point.

@Swanty
Copy link

Swanty commented Nov 2, 2022

Issam,

Thanks for clarification. Unfortunately I must confirm that this is no-go simple because njs is intended to be a supplementary tool for njs code development that runs inside nginx. And nginx won't be able to run external programs for any foreseeable future.

Is this still the case? There is a lot of limitations if we can't execute shell commands, for example fs.mkdirSync doesn't have a simple option recursive, but if there was an executeSync function then I could just run executeSync('mkdir -p "/non/existant/path"')

I'm trying to migrate from openresty to njs, but this limitation makes it impossible to migrate.

I could, in theory, create a node.js server that accepts shell commands as HTTP requests, but that's unnecessary extra work :/

@FJEagle
Copy link

FJEagle commented Nov 15, 2023

Issam,
Thanks for clarification. Unfortunately I must confirm that this is no-go simple because njs is intended to be a supplementary tool for njs code development that runs inside nginx. And nginx won't be able to run external programs for any foreseeable future.

Is this still the case? There is a lot of limitations if we can't execute shell commands, for example fs.mkdirSync doesn't have a simple option recursive, but if there was an executeSync function then I could just run executeSync('mkdir -p "/non/existant/path"')

I'm trying to migrate from openresty to njs, but this limitation makes it impossible to migrate.

I could, in theory, create a node.js server that accepts shell commands as HTTP requests, but that's unnecessary extra work :/

I use nginx+fcgi as workaround if it helps. fcgi should be more lightweight than an extra nodejs server as backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants