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.
- Features
- Deployment Status
- Tech Stack
- Project Structure
- API Endpoints
- Azure Deployment
- Local Setup
- Environment Variables
- Screenshots
- Author
- 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
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:
- View the Screenshots section to see the working application
- Follow the Local Setup Guide to run it on your machine
- Check the Azure Deployment section to understand the cloud architecture
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
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)
| 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 |
{
"name": "John Doe",
"position": "Software Engineer",
"department": "IT",
"salary": 75000,
"email": "john.doe@company.com"
}{
"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"
}
]
}- Created Azure SQL Server and Database instance via Azure Portal
- Configured firewall rules:
- Added Azure App Service IP addresses
- Whitelisted local development IP
- Created
Employeestable with appropriate schema - Secured connection strings in Azure Key Vault (or App Service Configuration)
- Created Linux-based App Service Plan (B1 tier)
- Deployed Node.js application using:
- GitHub Actions for CI/CD
- Direct deployment from Visual Studio Code
- Configured Application Settings (Environment Variables):
DB_USER,DB_PASSWORD,DB_SERVER,DB_NAME
- Enabled Application Insights for monitoring and logging
- 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
Follow these steps to run the project on your local machine:
- Node.js (v14 or higher) installed
- Azure SQL Database or local SQL Server instance
- Git installed
1. Clone the Repository
git clone https://github.com/Xavious2604/employee-api.git
cd employee-api2. Install Dependencies
npm install3. 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=development4. 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 dev6. 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}'| 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 |
Since the live deployment is currently offline, here are screenshots demonstrating functionality:
GET Request - Retrieve All Employees:
POST Request - Create New Employee:
Delete Request - Delete Exsisting Employee:
- 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
Xavious2604
- GitHub: @Xavious2604
- Project Link: https://github.com/Xavious2604/employee-api
This project is open source and available under the MIT License.
- 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!