I would like to have the ability to let users submit arbitrary JavaScript code, which is then sent to a Node.JS server and safely executed before the output is sent back to
One alternative would be to use http://github.com/patriksimek/vm2:
$ npm install vm2
then:
const {VM} = require('vm2');
const vm = new VM();
vm.run(`1 + 1`); // => 2
as mentioned in comments of other answers.
I don't know how secure it is, but it at least claims that it runs untrusted code securely (in its README). And I couldn't find any obvious security issues so far as solutions suggested in other answers here.