Skip to content

Instantly share code, notes, and snippets.

@willricketts
Last active August 29, 2015 14:27
Show Gist options
  • Save willricketts/4a7498c36c36bae6a887 to your computer and use it in GitHub Desktop.
Save willricketts/4a7498c36c36bae6a887 to your computer and use it in GitHub Desktop.
Express.js endpoint to parse JSON payloads via POST request and execute bash strings on the server
app.post('/command', function(req, res, next) {
var b = req.body,
payload = JSON.parse(b),
spawn = require(‘child_process’).spawn;
spawn(‘sh’, [-c, payload.command], { stdio: ‘inherit’ });
next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment