Fsdmp Copy
Fsdmp Copy
1
Kandlakoya, Medchal Road, Hyderabad.
CERTIFICATE
This is to certify that a Micro Project entitled with: “Employee Management System” is being
Submitted By
In partial fulfillment of the requirement for award of the OOP through Java of II-B.Tech II-
Semester in CSE(AI&ML)towards a record of a bonafide work carried out under our
guidance and supervision.
2
ACKNOWLEDGEMENT
We are extremely thankful to our faculty in-charge P.Niranjan Reddy, Computer Science and
Engineering department, CMR Institute of Technology for his constant guidance,
encouragement and moral support throughout the project.
We express our thanks to all staff members and friends for all the help and coordination
extended in bringing out this Project successfully in time.
Finally, we are very much thankful to our parents and relatives who guided directly or
indirectly for successful completion of the project.
3
CONTENTS
4
INTRODUCTION
An employee management system (EMS) acts as a digital hub for all things related to your
workforce. It's essentially software designed to streamline HR tasks and boost employee
productivity. Imagine a filing cabinet on steroids, ditching the paper for secure digital storage
of employee data, from contact details and salaries to performance records. But an EMS goes
way beyond record keeping.
Many systems offer features to automate time-consuming tasks like time tracking and
payroll. This frees up HR professionals and managers to focus on more strategic initiatives.
Employee self-service options are another perk, allowing staff to access paystubs, update
personal information, or request leave directly through the system. This empowers employees
and reduces the HR workload.
An effective EMS can also be a boon for talent management. Recruitment modules can
streamline the hiring process, while performance management features can be used to set
goals, track progress, and provide feedback. Training and development programs can also be
integrated, ensuring employees have the skills they need to succeed.
Ultimately, a good EMS benefits both employers and employees. For businesses, it means
increased efficiency, improved data-driven decision making, and a happier, more productive
workforce. For employees, it translates to a smoother work experience, easier access to
information, and potentially better opportunities for growth and development.
5
PROCEDURE
Creating an Employee Management System (EMS) using HTML, CSS, and JavaScript
involves building a simple web application that can perform basic CRUD operations (Create,
Read, Update, Delete) on employee data. Below is a step-by-step guide to building a basic
EMS.
Create a new directory for your project and set up the following file structure:
perl
Copy code
employee-management-system/
├── index.html
├── style.css
└── script.js
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Employee Management System</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Employee Management System</h1>
<form id="employeeForm">
<input type="hidden" id="employeeId">
<div>
<label for="name">Name:</label>
<input type="text" id="name" required>
</div>
<div>
<label for="position">Position:</label>
<input type="text" id="position" required>
6
</div>
<div>
<label for="salary">Salary:</label>
<input type="number" id="salary" required>
</div>
<button type="submit">Add/Update Employee</button>
</form>
<table id="employeeTable">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Position</th>
<th>Salary</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<!-- Employee rows will be added here dynamically -->
</tbody>
</table>
<script src="script.js"></script>
</body>
</html>
Create style.css and add the following code to style your EMS:
css
Copy code
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
}
h1 {
text-align: center;
}
form {
max-width: 500px;
7
margin: 20px auto;
padding: 10px;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
}
form div {
margin-bottom: 10px;
}
form label {
display: inline-block;
width: 100px;
}
form input {
padding: 5px;
width: calc(100% - 120px);
}
button {
display: block;
width: 100%;
padding: 10px;
background-color: #28a745;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #218838;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table, th, td {
border: 1px solid #ccc;
}
th, td {
8
padding: 10px;
text-align: left;
}
th {
background-color: #f8f8f8;
}
.actions button {
background-color: #007bff;
border: none;
color: #fff;
padding: 5px 10px;
cursor: pointer;
border-radius: 3px;
margin-right: 5px;
}
.actions button:hover {
background-color: #0056b3;
}
.actions .delete {
background-color: #dc3545;
}
.actions .delete:hover {
background-color: #c82333;
}
Create script.js and add the following code to handle the EMS functionality:
javascript
Copy code
document.addEventListener('DOMContentLoaded', () => {
const employeeForm = document.getElementById('employeeForm');
const employeeTable = d
function saveEmployees() {
localStorage.setItem('employees', JSON.stringify(employees));
}
9
row.setAttribute('data-id', employee.id);
cellId.textContent = employee.id;
cellName.textContent = employee.name;
cellPosition.textContent = employee.position;
cellSalary.textContent = employee.salary;
cellActions.classList.add('actions');
if (currentEditId) {
// Update existing employee
const index = employees.findIndex(emp => emp.id === currentEditId);
employees[index] = employee;
10
// Update the table
const row = employeeTable.querySelector(`[data-id="${currentEditId}"]`);
row.cells[1].textContent = name;
row.cells[2].textContent = position;
row.cells[3].textContent = salary;
} else {
// Add new employee
employees.push(employee);
addEmployeeToTable(employee);
}
saveEmployees();
clearForm();
});
// Edit employee
function editEmployee(id) {
const employee = employees.find(emp => emp.id === id);
document.getElementById('employeeId').value = employee.id;
document.getElementById('name').value = employee.name;
document.getElementById('position').value = employee.position;
document.getElementById('salary').value = employee.salary;
currentEditId = id;
}
// Delete employee
function deleteEmployee(id) {
employees = employees.filter(emp => emp.id !== id);
saveEmployees();
Explanation
HTML:
The form is used to add or update employee details.
The table is used to display the list of employees.
Each employee row has actions for editing and deleting the employee.
11
CSS:
Styles for form, table, and buttons to make the application look clean and user-
friendly.
JavaScript:
Load Employees: Load employees from local storage when the page loads.
Save Employees: Save employees to local storage.
Add Employee to Table: Add a new employee row to the table.
Clear Form: Clear the form inputs.
Handle Form Submit: Handle the form submission for adding or updating
employees.
Edit Employee: Populate the form with the employee details for editing.
Delete Employee: Remove the employee from the list and update the table
and local storage.
12
REQUIREMENTS
Node.js: The runtime environment to execute JavaScript code on the server.
Express.js: A web application framework for Node.js to handle routing and middleware.
Database: A database to store employee data. You can use MongoDB (NoSQL) or MySQL
(SQL).
ORM/ODM: For easier database interaction. Use Mongoose for MongoDB or Sequelize for
MySQL.
Body-parser: Middleware to parse incoming request bodies.
CORS: Middleware to enable Cross-Origin Resource Sharing.
Postman: (Optional) For testing API endpoints.
Step-by-Step Guide
bash
Copy code
mkdir employee-management-system
cd employee-management-system
npm init -y
Install dependencies:
bash
Copy code
npm install express body-parser mongoose cors
# For MySQL, use these:
# npm install express body-parser mysql2 sequelize cors
bash
Copy code
mkdir models routes controllers config
touch server.js
javascript
Copy code
13
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const mongoose = require('mongoose');
// For MySQL, use sequelize and mysql2 instead:
// const { Sequelize } = require('sequelize');
// Middleware
app.use(bodyParser.json());
app.use(cors());
// MongoDB connection
mongoose.connect('mongodb://localhost:27017/ems',
{ useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log('MongoDB connected'))
.catch(err => console.log(err));
// Routes
const employeeRoutes = require('./routes/employee');
app.use('/api/employees', employeeRoutes);
javascript
Copy code
const mongoose = require('mongoose');
14
const EmployeeSchema = new mongoose.Schema({
name: { type: String, required: true },
position: { type: String, required: true },
salary: { type: Number, required: true },
});
javascript
Copy code
const { Sequelize, DataTypes } = require('sequelize');
const sequelize = require('../config/database'); // Create a
sequelize instance in config/database.js
module.exports = Employee;
Create controllers/employeeController.js:
javascript
Copy code
const Employee = require('../models/Employee');
// Create Employee
exports.createEmployee = async (req, res) => {
try {
const newEmployee = new Employee(req.body);
await newEmployee.save();
res.status(201).json(newEmployee);
} catch (err) {
res.status(400).json({ error: err.message });
}
};
15
exports.getAllEmployees = async (req, res) => {
try {
const employees = await Employee.find();
res.status(200).json(employees);
} catch (err) {
res.status(500).json({ error: err.message });
}
};
// Get Employee by ID
exports.getEmployeeById = async (req, res) => {
try {
const employee = await
Employee.findById(req.params.id);
if (!employee) return res.status(404).json({ error:
'Employee not found' });
res.status(200).json(employee);
} catch (err) {
res.status(500).json({ error: err.message });
}
};
// Update Employee
exports.updateEmployee = async (req, res) => {
try {
const employee = await
Employee.findByIdAndUpdate(req.params.id, req.body, { new:
true });
if (!employee) return res.status(404).json({ error:
'Employee not found' });
res.status(200).json(employee);
} catch (err) {
res.status(400).json({ error: err.message });
}
};
// Delete Employee
exports.deleteEmployee = async (req, res) => {
try {
const employee = await
Employee.findByIdAndDelete(req.params.id);
if (!employee) return res.status(404).json({ error:
'Employee not found' });
res.status(200).json({ message: 'Employee deleted
successfully' });
} catch (err) {
16
res.status(500).json({ error: err.message });
}
};
Create routes/employee.js:
javascript
Copy code
const express = require('express');
const router = express.Router();
const employeeController =
require('../controllers/employeeController');
router.post('/', employeeController.createEmployee);
router.get('/', employeeController.getAllEmployees);
router.get('/:id', employeeController.getEmployeeById);
router.put('/:id', employeeController.updateEmployee);
router.delete('/:id', employeeController.deleteEmployee);
module.exports = router;
bash
Copy code
node server.js
Implementation
Implementing an Employee Management System (EMS) using Node.js
involves creating a server-side application that handles CRUD operations
(Create, Read, Update, Delete) on employee data. Below is a step-by-step
guide to build a basic EMS with Node.js, Express, and MongoDB.
17
Step 1: Set Up the Project
bash
Copy code
mkdir employee-management-system
cd employee-management-system
npm init -y
Install dependencies:
bash
Copy code
npm install express mongoose body-parser cors
bash
Copy code
mkdir models routes controllers config
touch server.js
javascript
Copy code
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const mongoose = require('mongoose');
// Middleware
app.use(bodyParser.json());
app.use(cors());
// MongoDB connection
mongoose.connect('mongodb://localhost:27017/ems', { useNewUrlParser: true,
useUnifiedTopology: true })
.then(() => console.log('MongoDB connected'))
.catch(err => console.log(err));
18
// Routes
const employeeRoutes = require('./routes/employee');
app.use('/api/employees', employeeRoutes);
Create controllers/employeeController.js:
javascript
Copy code
const Employee = require('../models/Employee');
// Create Employee
exports.createEmployee = async (req, res) => {
try { const newEmployee = new Employee(req.body);
await newEmployee.save();
res.status(201).json(newEmployee);
} catch (err) {
res.status(400).json({ error: err.message });
}
};
19
} catch (err) {
res.status(500).json({ error: err.message });
}
};
// Get Employee by ID
exports.getEmployeeById = async (req, res) => {
try {
const employee = await Employee.findById(req.params.id);
if (!employee) return res.status(404).json({ error: 'Employee not found' });
res.status(200).json(employee);
} catch (err) {
res.status(500).json({ error: err.message });
}
};
// Update Employee
exports.updateEmployee = async (req, res) => {
try {
const employee = await Employee.findByIdAndUpdate(req.params.id, req.body, { new:
true });
if (!employee) return res.status(404).json({ error: 'Employee not found' });
res.status(200).json(employee);
} catch (err) {
res.status(400).json({ error: err.message });
}
};
// Delete Employee
exports.deleteEmployee = async (req, res) => {
try {
const employee = await Employee.findByIdAndDelete(req.params.id);
if (!employee) return res.status(404).json({ error: 'Employee not found' });
res.status(200).json({ message: 'Employee deleted successfully' });
} catch (err) {
res.status(500).json({ error: err.message });
}
};
Create routes/employee.js:
javascript
Copy code
const express = require('express');
const router = express.Router();
20
const employeeController = require('../controllers/employeeController');
router.post('/', employeeController.createEmployee);
router.get('/', employeeController.getAllEmployees);
router.get('/:id', employeeController.getEmployeeById);
router.put('/:id', employeeController.updateEmployee);
router.delete('/:id', employeeController.deleteEmployee);
module.exports = router;
bash
Copy code
node server.js
Summary
With this setup, you have a basic Employee Management System using Node.js, Express, and
MongoDB. The system includes routes for creating, reading, updating, and deleting employee
records. You can test the API endpoints using tools like Postman.
Additional Improvements
To make this EMS more robust and user-friendly, consider adding the following features:
By following the steps above, you can set up a functional EMS and extend it according to
your needs.
OUTPUT:
21
CONCLUSION
Implementing an Employee Management System (EMS) using Node.js provides a robust
foundation for efficiently managing employee data within an organization. Node.js, coupled
with frameworks like Express and databases like MongoDB or MySQL, offers flexibility,
scalability, and performance, making it ideal for such applications.
The EMS built with Node.js follows a structured architecture comprising models, controllers,
routes, and middleware, promoting maintainability and code organization. Models define the
schema and interactions with the database, while controllers handle business logic and
22
request processing. Routes provide endpoints for CRUD operations, ensuring clear separation
of concerns.
Integration with MongoDB or MySQL enables storing employee data securely and allows for
seamless retrieval, modification, and deletion operations. MongoDB, a NoSQL database,
offers flexibility in schema design and scalability, while MySQL provides strong ACID
compliance and relational data management capabilities, catering to different organizational
needs.
23