Simple NodeJS Example

Re: Simple NodeJS Example

by Richard Lobb -
Number of replies: 0

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#@>#"

with

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

34

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.

Richard