Skip to content

Xavious2604/employee-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏒 Employee Management API

Node.js Express.js Azure SQL Azure App Service

A robust RESTful API for managing employee data with full CRUD operations. Built with Node.js, Express.js, and Azure SQL Database, and deployed on Azure App Service.


πŸ“‹ Table of Contents


✨ Features

  • CRUD Operations: Create, Read, Update, and Delete employee records
  • RESTful Architecture: Clean and intuitive API design
  • Cloud-Native: Fully deployed on Microsoft Azure
  • Secure: Environment-based configuration for sensitive credentials
  • Scalable: Hosted on Azure App Service with Azure SQL Database backend
  • MVC Pattern: Organized code structure following best practices

⚠️ Deployment Status

Current Status: πŸ”΄ Offline (Cost Optimization)

Note: This project was successfully deployed and tested on Azure Cloud. The live deployment has been paused to avoid ongoing costs associated with Azure SQL Database and App Service.

You can:


πŸ› οΈ Tech Stack

Backend:

  • Node.js - JavaScript runtime
  • Express.js - Web application framework
  • mssql - Microsoft SQL Server client for Node.js

Database:

  • Azure SQL Database - Managed relational database service

Cloud Infrastructure:

  • Azure App Service - PaaS for hosting web applications
  • Azure SQL Server - Database server management

Development Tools:

  • Postman - API testing
  • Visual Studio Code - Code editor
  • Git & GitHub - Version control

πŸ“‚ Project Structure

EMPLOYEE-API/
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   └── employeeController.js    # Business logic for employee operations
β”‚   β”‚
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── employeeModel.js         # Database queries and schema
β”‚   β”‚
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   └── employeeRoutes.js        # API route definitions
β”‚   β”‚
β”‚   └── app.js                       # Express app configuration
β”‚
β”œβ”€β”€ index.js                         # Application entry point
β”œβ”€β”€ package.json                     # Dependencies and scripts
β”œβ”€β”€ .gitignore                       # Git ignore rules
└── README.md                        # Project documentation

Architecture Pattern: MVC (Model-View-Controller)


πŸ”Œ API Endpoints

HTTP Method Endpoint Description Request Body
GET /api/employees Retrieve all employees None
GET /api/employees/:id Get employee by ID None
POST /api/employees Create new employee JSON (name, position, salary, etc.)
PUT /api/employees/:id Update employee details JSON (fields to update)
DELETE /api/employees/:id Delete employee None

Example Request (POST):

{
  "name": "John Doe",
  "position": "Software Engineer",
  "department": "IT",
  "salary": 75000,
  "email": "john.doe@company.com"
}

Example Response (GET):

{
  "success": true,
  "data": [
    {
      "id": 1,
      "name": "John Doe",
      "position": "Software Engineer",
      "department": "IT",
      "salary": 75000,
      "email": "john.doe@company.com",
      "created_at": "2024-01-15T10:30:00Z"
    }
  ]
}

☁️ Azure Deployment Workflow

1. Azure SQL Database Setup

  1. Created Azure SQL Server and Database instance via Azure Portal
  2. Configured firewall rules:
    • Added Azure App Service IP addresses
    • Whitelisted local development IP
  3. Created Employees table with appropriate schema
  4. Secured connection strings in Azure Key Vault (or App Service Configuration)

2. Azure App Service Deployment

  1. Created Linux-based App Service Plan (B1 tier)
  2. Deployed Node.js application using:
    • GitHub Actions for CI/CD
    • Direct deployment from Visual Studio Code
  3. Configured Application Settings (Environment Variables):
    • DB_USER, DB_PASSWORD, DB_SERVER, DB_NAME
  4. Enabled Application Insights for monitoring and logging

3. Security Best Practices

  • No hardcoded credentials in source code
  • Environment variables stored in Azure App Service Configuration
  • SQL Server firewall configured with minimal required access
  • HTTPS enforced for all API requests

πŸ’» Local Setup Guide

Follow these steps to run the project on your local machine:

Prerequisites

  • Node.js (v14 or higher) installed
  • Azure SQL Database or local SQL Server instance
  • Git installed

Installation Steps

1. Clone the Repository

git clone https://github.com/Xavious2604/employee-api.git
cd employee-api

2. Install Dependencies

npm install

3. Configure Environment Variables

Create a .env file in the root directory:

DB_USER=your_database_username
DB_PASSWORD=your_database_password
DB_SERVER=your_server.database.windows.net
DB_NAME=your_database_name
DB_PORT=1433

PORT=3000
NODE_ENV=development

4. Set Up Database

Run this SQL script to create the employees table:

CREATE TABLE Employees (
    id INT PRIMARY KEY IDENTITY(1,1),
    name NVARCHAR(100) NOT NULL,
    position NVARCHAR(100),
    department NVARCHAR(100),
    salary DECIMAL(10, 2),
    email NVARCHAR(100),
    created_at DATETIME DEFAULT GETDATE()
);

5. Start the Server

# Using Node
node index.js

# OR using Nodemon (if installed)
npm run dev

6. Test the API

The server will run at http://localhost:3000

Test with Postman or cURL:

# Get all employees
curl http://localhost:3000/api/employees

# Create new employee
curl -X POST http://localhost:3000/api/employees \
  -H "Content-Type: application/json" \
  -d '{"name":"Jane Smith","position":"Manager","salary":85000}'

πŸ” Environment Variables

Variable Description Example
DB_USER Database username admin
DB_PASSWORD Database password SecurePass123!
DB_SERVER SQL Server hostname myserver.database.windows.net
DB_NAME Database name EmployeeDB
DB_PORT SQL Server port 1433
PORT Application port 3000
NODE_ENV Environment mode development or production

πŸ“Έ Screenshots

Since the live deployment is currently offline, here are screenshots demonstrating functionality:

API Testing in Postman

GET Request - Retrieve All Employees:

Postman GET Request

POST Request - Create New Employee:

Postman POST Request

Delete Request - Delete Exsisting Employee:

Postman DELETE Request


πŸš€ Future Enhancements

  • Add authentication and authorization (JWT)
  • Implement pagination for large datasets
  • Add data validation and error handling middleware
  • Create comprehensive unit and integration tests
  • Add API documentation with Swagger/OpenAPI
  • Implement caching with Redis
  • Add logging with Winston or Morgan

πŸ‘€ Author

Xavious2604


πŸ“„ License

This project is open source and available under the MIT License.


πŸ™ Acknowledgments

  • Microsoft Azure for cloud infrastructure
  • Node.js and Express.js communities
  • All contributors and supporters of this project

⭐ If you find this project helpful, please consider giving it a star!

About

🏒 A RESTful API for employee management with full CRUD operations. Built with Node.js, Express.js, and Azure SQL Database. ☁️ Deployed on Azure App Service with secure cloud architecture.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors