You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Please note only Node.js code is supported here
async function run(msg, cfg, snapshot) {
console.log('Hello code, incoming message is msg=%j', msg);
let s = "abc";
let buff = Buffer.from(s);
let base64data = buff.toString('base64');
// Create message to be emitted
var data = messages.newMessageWithBody({message: base64data});
// Emit the data event
emitter.emit('data', data);
// No need to emit end
console.log('Finished execution');
}
One would expect it to produce a message {message: 'YWJj'}. However, instead it produces
ReferenceError: Buffer is not defined
at evalmachine.<anonymous>:8:12
at ContextifyScript.Script.runInContext (vm.js:32:29)
at Object.runInContext (vm.js:87:6)
because we forgot to bring Buffer and some other Node globals into the context in which the code is executed.
The text was updated successfully, but these errors were encountered:
Consider the following code:
One would expect it to produce a message
{message: 'YWJj'}
. However, instead it producesbecause we forgot to bring
Buffer
and some other Node globals into the context in which the code is executed.The text was updated successfully, but these errors were encountered: