This is a simple api that performs basic crud operations on employee data
- Nodejs
- MySQL
-
Create your database and add the following code to create an "employee" table.
CREATE TABLE IF NOT EXISTS `employees` ( `id` BIGINT UNSIGNED AUTO_INCREMENT, `first_name` VARCHAR(255) NOT NULL, `last_name` VARCHAR(255) NOT NULL, `email` VARCHAR(255) NOT NULL, `phone` VARCHAR(50) NOT NULL, `organization` VARCHAR(255) NOT NULL, `designation` VARCHAR(100) NOT NULL, `salary` DECIMAL(11,2) UNSIGNED DEFAULT 0.00, `status` TINYINT UNSIGNED DEFAULT 0, `is_deleted` TINYINT UNSIGNED DEFAULT 0, `created_at` DATETIME NOT NULL, `updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`)) ENGINE = InnoDB;
-
Edit the
db.config.js
file in the folder/src
and add your database name, username and password -
run
npm update
on your commandline:bash/cmd
npm update
- Now deploy your app by running
npm start
,start
command is defined in thepackage.json
file and runs thenodemon server
command
npm start
- The application can be accessed on this url http://localhost:5000
List all employees stored in database
GET /api/v1/employees:
Get a specific employee with employee_id
GET /api/v1/employees/<employee_id>:
Create employee
POST /api/v1/employees :
Update employee partially
PATCH /api/v1/employees/<employee_id>
Delete a employee
DELETE /api/v1/employees/<employee_id>
Update employee completely
PUT /api/v1/employees/<employee_id>