quizzy
v0.3.9
Published
Quizzes API server and SPA
Downloads
3
Readme
Quizzy
A simple quizzes API server and Single Page Application powered by Nodejs, Expressjs, Vuejs and Redis.
Prerequisite
Install NodeJS
Install
$ npm install quizzy
or
$ yarn add quizzy
Usage
Prerequisite : Populate the used redis db with some quizzes (alternative : use POST /quizzes API)
- Create a configured quizzy instance with Quizzy factory
- start() : starts the server
- stop() : closes the server
const Quizzy = require('quizzy')
const quizzy = Quizzy(/*myCustomConfig*/)
quizzy.start()
.then(() => {
console.log('ready!')
})
Features :
- Play a quiz session with the SPA
- Sign in with your Google, Twitter, or Facebook account
- Create and manage quizzes and sessions via APIs
- i18n compliant
Anatomy of the project
Help about the project structure
assets
Static assets (css, images, ...)
cli
This directory contains all the Single Page Application code powered by Vuejs.
The client part is based on VueJS with vue-i18n, vue-router, and vuex (it can also be used as a boilerplate project for VueJS)
- helper.js : util functions
- locales.yml : localized texts (vue-i18n)
- main.js : entry point of the single page app
- store.js : shared state of the single page app (vuex)
components
Vuejs used components
- account.vue : displays the account status (logged in)
- breadcrumb.vue : displays the breadcrumb links
- loading.vue : loading spinner
css
- style.css : styles applied to the single page app
views
Vuejs views
- home.vue : welcome view displayed for default routes and when not logged in
- quiz.vue : main vue that shows quiz questions and post answers to API server
- quiz-result.vue : shows the quiz result with score and evaluation if enabled in config
lib
This directory contains all the server code powered by Nodejs.
config
routes
Contains all the routes exposed by the express app, including APIs and OAuth2 endpoints
schemas
Contains all the JSON schemas of entities, in YAML format.
services
- store : Used to store the data model (quizzes and sessions) into memory or redis (feel free to code another implementation)
- index.js : Generic store interface
- memory-store.js : Simple store implementation in-memory
- redis-store.js : Store implementation for a Redis database server
- body-parser.js : Extended body parser compatible with JSON or YAML payload
- errors.js : Custom error classes used in the project
- json-validator.js : JSON schema validator used by the store to validate entities before persist them
- redis-cli.js : A simple Redis client
- view-renderer.js : Custom HTML view renderer powered by lodash template
config.js
Configuration loader
helper.js
Util functions
quizzy.js
Main module of the app. It exports a server component with a factory, init, start and stop methods if required by another module else it runs the server.
test
Unit tests in the form of mocha specs
views
Expressjs views used to render HTML pages
More information
The best way to understand how quizzy works is to have a look at unit tests
Build the project
Install dependencies :
$ npm install
or
$ yarn
Build the cli bundle :
$ npm run build
Note :
- The bundle file is created into assets/app directory
- if NODE_ENV is set to production, the bundle is uglyfied/minified without sourcemaps.
Start the server :
$ npm start
Note : if NODE_ENV is set to development, the server is started with nodemon and webpack middleware is used to hot reload the cli.
@tocomplete
Enjoy !