Skip to content
Lutfan Alaudin Naja edited this page Apr 1, 2026 · 1 revision

Employee Data Management App Wiki

Table of Contents

Overview

This is a CLI (Command Line Interface) application for managing employee data built with Node.js and MongoDB. It's a modern rewrite of a previous C++ project with enhanced features like bulk input, interactive editing, MongoDB persistence, and audit logging.

Key Technologies:

  • Node.js (v20+)
  • MongoDB Atlas + Mongoose ORM
  • Inquirer.js for interactive CLI
  • Modular service-based architecture

Project Structure

Employee-Data-Application-Project-JavaScript-based-node.js/
├── main.js                    # Main CLI entrypoint & menu
├── config/
│   └── db.js                  # MongoDB connection
├── models/                    # Mongoose schemas
│   ├── Employee.js
│   ├── DeletedEmployee.js     # Soft delete logs
│   └── EmployeeLog.js         # Audit trail
├── services/                  # Feature modules
│   ├── show-data.js
│   ├── add-data.js
│   ├── search-data.js
│   ├── edit-data.js
│   ├── delete-data.js
│   ├── sort-data.js
│   └── show-statistic.js
├── .env                       # MongoDB URI
├── package.json
├── README.md
└── LICENSE (MIT)

Setup Guide

Prerequisites

  • Node.js ≥ 20.x
  • MongoDB Atlas account (free tier)
  • Git (optional)

Step-by-Step Installation

# 1. Clone the 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. Setup MongoDB Atlas
#   a. Create free account at mongodb.com/atlas
#   b. Create cluster & database 'employeeDB'
#   c. Copy connection string
#   d. Create .env file
cp .env.example .env
# Edit .env: MONGO_URI=your_connection_string

# 4. Run the app
node main.js

Environment Variables

MONGO_URI=your_mongodb_connection_string_here

Usage Instructions

Main Menu Options

1. Tampilkan Semua Data      # View all employees
2. Tampilkan Statistik       # Employee statistics
3. Tambah Data Baru          # Add new employee(s)
4. Urutkan Data              # Sort by ID
5. Cari Karyawan             # Search by ID/Name
6. Edit Data                 # Edit existing employee
7. Hapus Data                # Delete employee
8. Keluar                    # Exit

Example Workflows

Adding Multiple Employees:

> Pilih jumlah data (0 = cancel): 2
> ID karyawan ke-1: EMP001
> Nama: John Doe
> Jabatan: Developer
> No Telp: 08123456789
> Save? [Y/n]: Y

Searching & Editing:

> Cari dengan ID/Nama: John
> Select employee: [1] John Doe (EMP001)
> Edit fields (Enter to skip):
> New Name: Jane Doe
> Confirm changes? [Y/n]: Y

Features

Feature Description Status
Bulk Input Add multiple employees at once
Smart Search ID or partial name matching
Interactive Edit Field-by-field editing w/ preview
Data Sorting Asc/Desc by ID, optional export
Statistics Count, job grouping, ID prefix
Audit Logging Track CREATE/UPDATE/DELETE
Soft Delete Log deleted records
Validation Unique IDs, required fields

Database Schema

Collections

employees

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

deletedemployees (logs)

{
  ID: String,
  NAMA: String,
  JABATAN: String,
  TELP: String,
  deleted_at: Date
}

employeelogs (audit)

{
  action: 'CREATE' | 'UPDATE' | 'DELETE',
  data_before: Object | null,
  data_after: Object | null,
  timestamp: Date
}

Code Architecture

main.js → Services → Models → MongoDB
     ↓
  inquirer prompts

Key Design Patterns:

  • Modular Services: Each feature in separate file
  • Repository Pattern: Models handle data access
  • Dependency Injection: Services imported in main.js
  • Async/Await: All DB operations are asynchronous

Development

Running in Development

npm install
npm run dev  # Add to package.json scripts

Adding New Features

  1. Create new service in /services/
  2. Add menu option in main.js
  3. Update README & Wiki

Testing

# Manual testing via CLI
node main.js

# Add Jest tests (future)
npm test

Deployment

Fully self-contained CLI app. No server deployment needed.

Troubleshooting

Issue Solution
Cannot connect to MongoDB Check .env URI, whitelist IP in Atlas
Module not found Run npm install
ID already exists Use unique ID format (EMP001, DEV002)
No data found Add sample data first

Common MongoDB Atlas Setup:

Network Access → Add IP → 0.0.0.0/0 (Allow all)
Database Access → Create user → Read/Write

License

This project is MIT licensed.