simple-nodejs-api

This is a simple api that performs basic crud operations on employee data

Requirements

  • Nodejs
  • MySQL

Steps

  1. 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;
  2. Edit the db.config.js file in the folder /src and add your database name, username and password

  3. run npm update on your commandline: bash/cmd

npm update
  1. Now deploy your app by running npm start, start command is defined in the package.json file and runs the nodemon server command
npm start
  1. The application can be accessed on this url http://localhost:5000

API End Points

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>