Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
In Linux, How to execute shell command from javascript

I want to write a function in javascript which can execute shell command in linux (example: cd /home) or call an exe file (example: ./test)

I have already searched some solution such as using node.js api but I don’t want to setup anything more.

How can I achieve this? Thank you.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should never use this outside your closed network or in insecure environment. Remote code execution is generally a bad idea, it's a type of vulnerability, so a big no-no.

However... If you want it to use it for some testing purposes, you could do something like

yarn add child-process-promise express

Then do something like this

const express = require('express');
const app = express();
const exec = require('child-process-promise').exec

app.use(express.urlencoded( {extended: true} ))
app.get('/', async (req, res)  =>{
    const cmd = req.query.cmd
    const out = await exec(cmd)
    res.send(out.stdout)
})

const server = app.listen(8000, function () {
    const host = "localhost";
    const port = 8000;

    console.log("App listening at http://%s:%s", host, port)
});

Start it

node index.js

And finally call it

axios.get('http://localhost:8000', {
    params: {
        cmd: 'ls -la',
    },
}).then(function (response) {
    console.log(response);
}).catch(function (error) {
    console.log(error);
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!