Skip to content

Creating a new module

Marius Coțofană edited this page Feb 22, 2016 · 3 revisions

In wouso.js a module is organised as a NPM module and it is composed of:

  • a backed API
  • a single page React.js app (optional)

Modules can be games included in the platform (e.g. qotd, quest) or core modules that bring extra functionality to the platform (e.g. wouso-social-login) or themes, that change the visual aspect of the platform (e.g. wouso-foundation).

Building the module and API endpoints

  1. Start by choosing the type of module you want to develop (core module, game or theme) and add it to the appropiate section in the /config.json file. In this example we will go with a new game module called quest.
"games": {
  "wouso-qotd" : true,
  "wouso-quest": true
}
  1. Create the module that will hold your new game. Remember it has to bee a NPM module, so don't forget the package.json file. Your module should also have a file defining the endpoints of your module, called routes.js. Let's add a test route:
var express = require('express');
var router  = express.Router();

router.get('/quest', function (req, res, next) {
  res.send('Welcome to my new module.')
});

module.exports = router;
  1. Link you new shiny module to the platform (as a NPM module), using the following command, from the root of the repo:
npm link modules/wouso-quest
  1. Start the app and check out your new module endpoint, at http://localhost:4000/quest

Creating the frontend

TODO:

Store date

TODO: module data, settings

Internationalisation

TODO:

Logging

There is a centralised logging system, which can be used by requiring the core/logging module from the repo.

var log = require('../../core/logging')('qotd')

To use it

log.info('User started game.')

Clone this wiki locally