d2 Starter app
Make sure you have at least the following versions of
- Node version v5.6.0 or higher
- npm version 3.8.0 or higher
Use the following commands to check your current versions
node -v npm -v
Clone the repository from github with the following command
git clone https://github.com/dhis2/app-skeleton
Install the node dependencies
To set up your DHIS2 instance to work with the development service you will need to add the development servers address to the CORS whitelist. You can do this within the DHIS2 Settings app under the access tab. On the access tab add
http://localhost:8081 to the CORS Whitelist.
The starter app will look for a DHIS 2 development instance configuration in
$DHIS2_HOME/config. So for example if your
DHIS2_HOMEenvironment variable is set to
~/.dhis2, the starter app will look for
~/.dhis2/config.jsonand load the first one it can find.
The config should export an object with the properties
authorization, where authorization is the base64 encoding of your username and password. You can obtain this value by opening the console in your browser and typing
If no config is found, the default
http://localhost:8080/dhisand the default username and password is
This should enable you to run the following node commands:
To run the development server
To run the tests one time
To run the tests continuously on file changes (for your BDD workflow)
npm run test-watch
To generate a coverage report for the tests
npm run coverage
To check the code style for both the JS and SCSS files run
npm run lint
Frameworks... and libraries
React is the view part of the front-end applications, it has a component based architecture. At DHIS2 we also use JSX syntax that is generally used with React.
d2 is the DHIS2 abstraction library that allows you to communicate with the DHIS2 api in a programatic way. d2-ui is the ui component library that is build on top of d2 to allow reuse of common components that are used within DHIS2 applications. d2-ui also contains our own application wiring code through its stores and actions.
d2-ui makes use of material-ui for rendering more basic components like TextFields and Lists. It is therefore quite useful to look into this library too when building DHIS2 apps and making use of d2-ui.
Webpack is a module bundler that allows the use of plugins to do various other things. We make use of webpack for the following things:
- Bundling the files up into a single file. (The primary webpack use case)
- Transpiling ES2015 and React JSX code to ES5 syntax so it runs in the browser. (This is done using Babel.)
- Loading Scss files. Scss is a css pre-processor that has quite some fancy features as variables, nesting of style declarations etc.
- Minifying the bundled file to reduce file size
- Remove duplicate dependencies
To make the development a more interactive experience we use
webpack-dev-server to provide us with a development server that watches the project files and refreshes the browser when changes are detected.
Npm is used as both a dependency management tool as a workflow manager through its
scripts as can be seen in the package.json. It provides convenience commands to kick off various tasks. These tasks are mentioned above as
npm run <command>,
npm test, etc.
mocha, chai, sinon
Mocha is a test runner that runs the unit tests. Chai is the assertion library that is used to do assertions within those tests. It supports various styles. At DHIS2 we generally tend to go with the expect/BDD variant. Sinon is used to do mocking within the tests and to fake HTTP requests where needed. The interesting things to look at for sinon are it's spies and stubs calls and the fakeServer.
Enzyme tool to make testing of React components easier. They provide a pretty clean api to get information from your rendered react components.