[Fixed] NodeJS Capture output of NODEJS Command and Display to express window

Issue

NOTE: I do not want to capture the output of a bash command, however a command like:

console.log(1)

And it just say 1 on my express server instead of logging it to the console

I am very very new to NodeJs but skilled in python

Here is my code:

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => {
  res.send(req.param('cmd')
})

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})

I want if I do:

prtc://my.server?cmd=console.log(1)

That page will display 1.
How would I do this?

Solution

Made it on my own with PHP.

For anyone who needs the code, run this on REPL.IT or HEROKU or of the like.

<?php
$lang = $_GET['lang'];
$command = $_GET['cmd'];

if ($lang == 'sh') {
  System($command);
};
if ($lang == 'python3') {
  System('python3 -c "'.$command.'"');
};
if ($lang == 'python2') {
  System('python2 -c "'.$command.'"');
};
if ($lang == 'node14') {
$fp = fopen('cmds.js', 'w');
fwrite($fp, $command);

System('node cmds.js');
unlink('cmds.js');
};
?>

Leave a Reply

(*) Required, Your email will not be published