Skip to content

Nekonepan/Employee-Data-Application-Project-JavaScript-based-node.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

63 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—‚οΈ Employee Data Management App - Node.js + MongoDB CLI

A feature-rich CLI (Command Line Interface) application for managing employee data using JavaScript (Node.js). This app is a rewrite and improvement of my previous project written in C++, with added enhancements like bulk input, interactive editing, real file persistence, and modular design.


πŸ“Œ Project Description

This project simulates a basic employee database management system that runs entirely in the terminal. It's designed for learning purposes, suitable for beginner-to-intermediate developers who want to understand:

  • How to structure CLI apps in Node.js
  • How to manage employee data with MongoDB using Mongoose ORM
  • How to modularize code and separate logic
  • How to mimic real-world HR-like data operations

🧬 Origin & Reference

This Node.js project is a refactored and modernized version of my previous C++ project:

πŸ” Rewritten From:

🎯 Enhancements Compared to C++ Version:

Feature C++ Version Node.js Version
Save to File βœ… TXT βœ… MongoDB via Mongoose
Employee Input βœ… Manual βœ… Single & Bulk Input
ID / Name Search βœ… Only by ID βœ… By ID & Name (with list selection)
Edit Data ❌ None βœ… Full interactive editing
Sort Data βœ… Yes (no persistence) βœ… With option to save results to file
Table View βœ… Static βœ… Dynamic with console.table()
Input Validation ❌ Very limited βœ… Rich & interactive validation
Log Deleted Data ❌ None βœ… Yes (DeletedEmployee collection)
Backup ❌ None βœ… Built-in via MongoDB timestamps/logs
Restore ❌ None βœ… Yes (from backup file with confirmation)

βš™οΈ Setup Requirements

  • βœ… Node.js installed (v20+ recommended)
  • βœ… MongoDB Atlas account (free: https://www.mongodb.com/atlas)
  • βœ… Basic terminal/command prompt
  • βœ… (Optional) Text editor like VS Code

πŸš€ How to Run the Project

1. Clone this repository

git clone https://github.com/Nekonepan/Employee-Data-Application-Project-JavaScript-based-node.js.git
cd Employee-Data-Application-Project-JavaScript-based-node.js

2. Install dependencies

npm install

3. Configure MongoDB

  1. Create free account at MongoDB Atlas
  2. Create cluster, get connection string
  3. Copy .env.example to .env and set MONGO_URI

4. Run the app

node main.js

πŸ“Œ You'll be guided through an interactive menu system.


πŸ“‚ Folder Structure

|-- main.js                          # Main application logic
|-- config/
|   `-- db.js                        # MongoDB connection
|-- models/
|   |-- Employee.js                  # Employee schema
|   |-- DeletedEmployee.js           # Deleted logs schema
|   `-- EmployeeLog.js               # Audit logs
|-- services/                        # Feature services
|-- package.json                     # Dependencies (mongoose, mongodb, etc.)
|-- .env                             # MongoDB URI
|-- node_modules/                    # Dependencies

βœ… Features Implemented

Feature Status
Input single & multiple data entries βœ…
Edit data with summary & confirmation βœ…
Search by ID or Name (list selection if duplicate) βœ…
Sort data by ID (ascending/descending, optional save) βœ…
Empty field validation & interactive prompts βœ…
Confirm before save or restore βœ…
Modularized functions per feature βœ…
MongoDB persistence & audit logging βœ…

βš™οΈ How the App Works

Here’s a simplified breakdown of the logic flow behind the app:

  1. πŸ“‚ Program connects to MongoDB Atlas via Mongoose on startup.
  2. πŸ“œ A main menu is displayed using inquirer, with options like View, Add, Search, Edit, Sort, Statistics, Backup/Restore, and Exit.
  3. πŸ“₯ When adding data:
    • User is asked how many records to add (input 0 = cancel)
    • Each input is validated (non-empty, unique ID)
    • Data is optionally saved after confirmation
  4. πŸ” When searching:
    • User can search by ID or Name (case-insensitive, partial match supported)
    • If multiple results are found (e.g., duplicate names), a list is displayed to select the correct record
  5. ✏️ When editing:
    • User selects data from search results (by ID or Name)
    • Empty inputs are ignored (retain original value)
    • A summary table is shown after edit
    • Confirmation is required before saving
  6. πŸ”ƒ When sorting:
    • User can choose Ascending or Descending by ID
    • Sorted result can be saved or discarded
  7. πŸ“Š Statistics:
    • Show total employee count
    • Group employees by job position
    • Count employees by ID prefix
  8. πŸ“ Data stored in MongoDB collections with Mongoose schemas for persistence and auditing.

The application runs in a loop until the user chooses to exit.


πŸ“ Data Format (MongoDB Collections)

Employee Collection (employees):

Mongoose schema:

ID: { type: String, required: true, unique: true }
NAMA: { type: String, required: true }
JABATAN: { type: String, required: true }
TELP: { type: String, required: true }
timestamps: true  // createdAt, updatedAt

Data stored as MongoDB documents matching the schema.

DeletedEmployee Collection (deletedemployees):

Mongoose schema:

ID: String
NAMA: String
JABATAN: String
TELP: String
deleted_at: { type: Date, default: Date.now }

Logs deleted records with timestamp.

EmployeeLog Collection (employeelogs):

Mongoose schema for change history:

action: { type: String, enum: ["CREATE", "UPDATE", "DELETE"] }
data_before: Object (null for CREATE)
data_after: Object (null for DELETE)
timestamp: { type: Date, default: Date.now }

Tracks all data modifications.


πŸ“Š Summary & Takeaways

  • πŸ”§ Implemented modular practices in a Node.js CLI application
  • πŸ’Ύ Built full CRUD system with MongoDB Atlas and Mongoose ORM
  • 🧠 Focused on algorithmic logic and data handling, not UI/Frontend
  • 🧰 Migrated from procedural C++ (TXT storage) into modular JavaScript (MongoDB database)
  • βœ… Finished with clean documentation, maintainable structure, and extensible design

🌱 Potential Future Enhancements

Development Ideas Status
πŸ”’ Add login system & user access rights ⏺️ ToDo
🧾 Export employee data to CSV/Excel ⏺️ ToDo
🌐 Migrate backend to Express + MongoDB βœ… Done
πŸ§ͺ Add unit testing with Jest ⏺️ ToDo

"These are planned features for future versions"


πŸ™‹ Author's Note

This project is currently marked as complete but may receive further updates. Feel free to fork, remix, or use it for your own learning.

If you want to know what the previous version of C++ looked like before it was refactored into Node.js, you can look at these two files:


πŸ™ Final Words

This project started as a simple C++ console app and has now evolved into a more modular, maintainable, and interactive CLI application using JavaScript and Node.js. It was built as a personal learning project, but it’s fully functional and easy to expand.

Whether you're here to learn, improve it, or just curious, thank you for stopping by!

If you like this project or find it useful, feel free to:

  • ⭐ Star the repository
  • πŸ› οΈ Fork it and build your own version
  • πŸ“¬ Reach out for questions or collaboration

Happy coding! πŸ’»βœ¨

About

CLI-based employee management system using Node.js, with MongoDB storage and full CRUD features.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors