Question Authors' Forum

Simple NodeJS Example

Picture of Richard Lobb
Re: Simple NodeJS Example
by Richard Lobb - Tuesday, 2 October 2018, 11:10 AM

Sorry Mark, it looks like nodejs support has fallen by the wayside a bit. NodeJS now enforces strict mode and the current CodeRunner nodejs prototype breaks. Fortunately, it's easy to fix.

If you have administrator rights on the Moodle system, navigate in the question bank to the category Top for System, where you should find a question BUILT_IN_PROTOTYPE_nodejs. Edit that question type (ignore the "Proceed at your own risk" warning) and replace the line in the template

SEPARATOR = "#<ab@17943918#@>#"


var SEPARATOR = "#<ab@17943918#@>#";

You should then be able to create a nodejs-2 CodeRunner question that says "Write a function add(n1, n2) that returns the sum of n1 and n2" with test cases like

console.log(add(23, 11));

and expected output


In case you don't have admin rights, I attach an xml file that you can import. It defines the fixed nodejs prototype (defining a question type nodejs rather than nodejs-2) and the add() example question. 

Sorry about the hassles. I'll fix the prototype in the next release and add the sample question.