Today happens to be the international nodeschool day and hence this post!

There are many ways of creating a nodeschool workshop, in this post I shall walk you through the steps of creating a workshop using a module /me authored named adventure-runner

First up install the module: npm install --save adventure-runner

All you need in your workshop root:

runner.js: The brain of the workshop.

problems dir: Where all your problems are located.

package.json: Like any other module.

runner.js would be like:

1 2 3 var runner = require ( 'adventure-runner' ); runner ( 'example-adventure' ,[ 'dinosaurs' , 'robots' , 'wowsers' ]);

or

1 2 3 var runner = require ( 'adventure-runner' ); runner ( 'example-adventure' , './problems' );

P.S: Use the first variant if the order of the problems are important.

The problems dir will have sub dirs of problem in it, in our example the diansaurs dir must have a index.js in that, which would:

Exports problem statement with exports.problem

Exports verify function exports.verify = function(args, cb) where args would be the args passed from the CLI to verify and cb would decide if the solution to the problem was proper or not.

Let's create a simple nodeschool adventure, called adventure-math :

Basic dir setup:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 # Create a dir named adventure-math and cd into it. mkdir adventure-math && cd $_ # Create a empty package.json and install the deps. echo {} > package.json npm install adventure-runner # Create a `runner.js` touch runner.js # Create a problems dir and cd into it ( mkdir problems && cd $_ # Create a addition problem dir with index.js in it. mkdir addition touch addition/index.js )

Write some code:

Fill the runner.js with the style you intent to use.

1 2 3 var runner = require ( 'adventure-runner' ); runner ( 'math-adventure' , './problems' );

Fill the problems/index.js with the problem.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 var pwd = require ( 'process' ). cwd (); // Problem def, quick tip use ES6 template strings. exports . problem = 'Write a program that adds two given numbers:



' + '* Create a file `add.js` which returns the sum of two numbers



' + '* Don\'t forget to export you function. module.exports = function() {}`);



' + 'Finally to verify do a `math-adventure verify add.js`



' ; // Verifier exports . verify = function ( args , cb ) { // Propose solution var proposed = require ( pwd + '/' + args [ 0 ]); // Check if the solution is correct. if ( proposed ( 3 , 4 ) == 7 ) { console . log ( "You have solved it!" ); return cb ( true ); } else { console . log ( "Sorry, your solution is wrong :(" ); } };

Mention the bin property in your package.json along with other fields, so that it looks something like below [Even better if you had used npm init ;)] :

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 { "name" : "adventure-math" , "version" : "0.0.0" , "description" : "Learn your math!" , "bin" : { "adventure-math" : "runner.js" }, "author" : "Hemanth.HM < [email protected] >" , "license" : "MIT" , "keywords" : [ "nodeschool" , "adventure" , "education" , "math" , "fun" ], "dependencies" : { "adventure-runner" : "^2.0.0" } }

Final steps:

npm link to link the binary and now you must see something like below on executing adventure-math on your CLI.

The user is expected to write the solution and verify it for themselves ;)

Hope you liked the post, feel free to modify the flow as per your need.

For the lazy ones here are few links:

adventure-ruuner-boilerplate boilerplate for the code mentioned above.

interview-time a module written using adventure-runner which would help you to practice for your technical interviews.

That's it for now, happy node-schooling! :)