Need private packages and team management tools?Check out npm Teams »


0.0.5 • Public • Published

Code Challenge

NPM version Build status Test coverage Gittip

Install, run and share command line challenges. Perfect for learning, practicing or teaching others how to code.


You will need to install node.js. Once done, you can use npm to install the module globally and use the command line interface.

npm install -g code-challenge


challenge select   # Select a challange to use 
challenge exercise # Select an exercise to run 
challenge print         # Print the currently selected exercise 
challenge run [args]    # Run your solution in a test environment 
challenge verify [args] # Check your solution is correct 
challenge help  # Help menu 
challenge reset # Reset everything 
challenge next # Move to the next exercise 
challenge prev # Move to the previous exercise 

To get started, try installing your first challenge. I'd recommend Project Euler using npm install -g code-challenge-euler.

Create Your Own Challenge

To create a custom challenge pack to share, you'll need to create a new npm module and add code-challenge as a dependency. The module name must be prefixed with code-challenge- to automatically be loaded. The modules main file should require code-challenge, set the challenge title and add exercises.

var assert    = require('assert');
var challenge = require('code-challenge');
challenge.title = 'Example Challenge';
challenge.exercise('First Exercise')
  .add('print', function () {
    return challenge.renderFile(__dirname + '/exercises/');
  .add('verify', function () {
    return challenge.execFile(this._[0])
      .spread(function (stdout) {
        assert.equal(stdout, 'Example output\n');
challenge.exercise('Tenth Exercise')
  .add('print', ...)
  .add('verify', ...);

Rendering Any File

Challenge comes with a renderFile method that supports rending content from a file with standard syntax highlighting and colours.

Executing Any File

Challenge support executing most programming languages based on the file name automatically. By using the execFile or spawnFile methods, your challenge will be future proof and support all possible languages.

Failing an Exercise

When running the verification task, you can throw an error, reject a promise, error in a stream or pass an error as the first parameter of the callback to provide feedback.


Code challenge was originally inspired by all the work put into learnyounode, stream-adventure and gulp.




npm i code-challenge

DownloadsWeekly Downloads






Last publish


  • avatar