Server side (express app) for easydonor-react SPA (https://github.com/dpetrini/react-easydonor).
- Language - JavaScript/NodeJS
- Express server
- MongoDB with mongojs driver
- Pug templates
- Socket.io for real time updates
The application isserver side for React app dpetrini/easydonor-react The source files are divided in folders inside js/source directory as follows:
- bin: executable file
- config: files to hold environment variables like which mongo db server to use
- controllers: the C of MVC, holds the logic to interface react client app to database
- db: holds the connection to mongo db
- models: M of MVC, holds real connection to db and other server related functions.
- public: file that holds the react client app when in production
- routes: express routes for this app
- tests: unit and api tests, mocha based (not complete yet)
- views: temporaty pug views for data handling in server
List all donors in raw text.
HTTP | Value |
---|---|
Body | { "_id", "firstName", "lastName", "contactNumber", "emailAddress", "bloodGroup"} |
List all donors in nice HTML table.
HTTP | Value |
---|---|
Body | { "_id", "firstName", "lastName", "contactNumber", "emailAddress", "bloodGroup"} |
Create a donor.
Body Param | Description |
---|---|
firstName | First name |
lastName | Last name |
contactPhone | Phone number |
emailAddress | Email address |
bloodGroupd | blood group for donor |
HTTP | Value |
---|---|
Body | { "_id", "firstName", "lastName", "contactNumber", "emailAddress", "bloodGroup"} |
Update donor data.
Body Param | Description |
---|---|
firstName | First name |
lastName | Last name |
contactPhone | Phone number |
emailAddress | Email address |
bloodGroupd | blood group for donor |
HTTP | Value |
---|---|
Body | { "_id", "firstName", "lastName", "contactNumber", "emailAddress", "bloodGroup"} |
Delete donor by id.
HTTP | Value |
---|---|
Status Code | 200 |
Entry points for register management - get donor data for edit if pug form.
HTTP | Value |
---|---|
Body | { "_id", "firstName", "lastName", "contactNumber", "emailAddress", "bloodGroup"} |
Entry points for register management - send donor edited in pug form.
Body Param | Description |
---|---|
firstName | First name |
lastName | Last name |
contactPhone | Phone number |
emailAddress | Email address |
bloodGroupd | blood group for donor |
HTTP | Value |
---|---|
Body | { "_id", "firstName", "lastName", "contactNumber", "emailAddress", "bloodGroup"} |
Get status from running app.
HTTP | Value |
---|---|
Body | { "app status..."} |
Before testing or running the service should be properly configured with following environment variables.
Key | Value | Description |
---|---|---|
process.env.NODE_ENV | production or development or test |
Defines the API entry points for testing or production. |
DEBUG | users:* |
Use to enable debug messages. |
Mocha, instanbul, converage
1) Run Unit Tests
mocha tests/unit/*
2) Run Unit Tests with DEBUG (maybe polluted)
export DEBUG=donors:* && mocha tests/unit/*
3) Run API (integrated tests โ Supertest for Express & Cloud Mongo DB)
(please DO export NODE_ENV as preventing it will damage database)
export NODE_ENV=test && mocha tests/api/*"
4) Same as above with DEBUG
export DEBUG=donors:* && export NODE_ENV=test && mocha tests/api/*
5) Create COVERAGE tests and HTML reports (with nyc/istanbul)
(Then check ./converage/index.html)
nyc --reporter=html --reporter=text mocha tests/unit/*
export NODE_ENV=test && nyc --reporter=html --reporter=text mocha tests/api/*
Download this repository. And export the above environment variables, then make sure to open react app.
Using npm:
> npm install
> npm run nodemon (or)
> npm start
Open in your browser
http://localhost:3000
http://127.0.0.1:3000/donors/
- Create support in Model for GeoSpatial coordinates to provide lazy loading (only loads the current view donor points).