This project provides backend and frontend applications to manage employees.
- The home page lists all available employees from the datastore. Also, it provided a form to add a new employee.
- While creating a new Employee, only
firstname
,lastname
,hiredate
androle
should be provided and the request is sent to the backend Employee API. - Employee API adds a quote and a joke for the create employee request using external quotes and jokes APIs.
- Also, field validations are implemented such as hiredate (current or past - no future dates), required fields, and only one CEO possible.
- Employee 'Edit' and 'Delete' functionalities are also available.
- All records are stored in a local datastore. Storage is persistent using
node-persist
npm package.
- NodeJS - backend/server app provides a REST API using the express router and node-persist storage
- ReactJS - frontend/client app lists existing employees and provides UI to perform CRUD operations using React Hooks
node
&npm
- With the installation of the node, npm is by default installed.
- Verify using the commands:
node -v
&npm -v
- (Application tested on)
$ npm -v 6.13.4 $ node -v v12.16.1
In the project root directory, run:
cd client
npm ci
cd ..
npm ci
npm start
npm ci
installs npm packages and createsnode_modules
directory for both server and client apps. Ifnpm ci
gives any dependency error, use thenpm install
command instead of it.npm start
command works as below for this application:- Concurrently starts NodeJS (server) and ReactJS (client) applications.
- NodeJS server application first runs unit tests before starting the server on port
3001
. - ReactJS client application runs on the port
3000
.
- Once all steps are completed successfully, our Employee App is launched at http://localhost:3000
- API Documentation (Swagger UI) is available at http://localhost:3001/api-docs
docker
&docker-compose
- Verify using the commands:
docker -v
&docker-compose -v
$ docker -v Docker version 20.10.5, build 55c4c88 $ docker-compose -v docker-compose version 1.29.0, build 07737305
- Verify using the commands:
In the project root directory, run:
docker-compose up
docker-compose down
docker-compose up --build
Using mocha
, chai
, and supertest
npm packages, created unit tests for the Employee API.
In the project root directory, run: npm test
Output:
Employee API
✓ should create a new employee to the db. POST /api/employee (778ms)
✓ should return all employees. GET /api/employee
✓ should find an employee by a unique id. GET /api/employee/:id
✓ should update an employee by a unique id. PUT /api/employee/:id
✓ should delete an employee by a unique id. DELETE /api/employee/:id
Create a new employee
✓ should have called an external quotes api
✓ should have called an external jokes api
7 passing (799ms)
Once the application starts, Swagger UI will be available at http://localhost:3001/api-docs.