{"id":27841388,"url":"https://github.com/tvatdci/node-farm","last_synced_at":"2026-02-20T09:32:42.480Z","repository":{"id":287490264,"uuid":"964800624","full_name":"TVATDCI/node-farm","owner":"TVATDCI","description":"This project is a beginner-friendly implementation of a basic Node.js server that serves a product overview page and prepares for product detail pages. It demonstrates how to use Node.js to read files, serve HTML templates, and handle basic routing without any external frameworks.","archived":false,"fork":false,"pushed_at":"2025-04-23T13:30:12.000Z","size":91,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-21T07:08:41.577Z","etag":null,"topics":["api-server","asynchronous","content-type","dirname","error-handling","html","javascript","json-data","json-parser","json-stringify","nodejs","readfilesync","synchronous","top-level-await","writefilesync"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TVATDCI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-11T20:06:58.000Z","updated_at":"2025-04-23T13:30:16.000Z","dependencies_parsed_at":"2025-04-12T03:29:43.211Z","dependency_job_id":"3b5225d2-71ef-410f-9fce-f5a6fd212e0f","html_url":"https://github.com/TVATDCI/node-farm","commit_stats":null,"previous_names":["tvatdci/node-farm"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/TVATDCI/node-farm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TVATDCI%2Fnode-farm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TVATDCI%2Fnode-farm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TVATDCI%2Fnode-farm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TVATDCI%2Fnode-farm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TVATDCI","download_url":"https://codeload.github.com/TVATDCI/node-farm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TVATDCI%2Fnode-farm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29647742,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-20T09:27:29.698Z","status":"ssl_error","status_checked_at":"2026-02-20T09:26:12.373Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-server","asynchronous","content-type","dirname","error-handling","html","javascript","json-data","json-parser","json-stringify","nodejs","readfilesync","synchronous","top-level-await","writefilesync"],"created_at":"2025-05-03T04:59:18.383Z","updated_at":"2026-02-20T09:32:42.464Z","avatar_url":"https://github.com/TVATDCI.png","language":"HTML","readme":"# Node-farm\n\n\u003cp align=\"left\"\u003e\n\u003cimg src=\"./assets/js.svg\" alt=\"JavaScript Logo\" width=\"50\" /\u003e\n\u003cimg src=\"./assets/node-js.svg\" alt=\"NodeJs Logo\" width=\"50\" style=\"margin-left: 5px;\"/\u003e\n\u003cimg src=\"./assets/html-5.svg\" alt=\"HTML-5 Logo\" width=\"50\" style=\"margin-left: 5px;\"/\u003e\n\u003cimg src=\"./assets/css-3.svg\" alt=\"CSS-3 Logo\" width=\"50\" style=\"margin-left: 5px;\"/\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"./assets/green-ani.svg\" alt=\"About me\" width=\"50\" align=\"left\" style=\"margin-right: 5px;\"/\u003e\n\u003c/p\u003e\n\nHere’s a beginner-friendly `README.md` file for your project. It explains the purpose, setup, and functionality of your project in a simple and clear way.\n\n---\n\n## Beginner friendly:\n\nThis project is a beginner-friendly implementation of a basic Node.js server that serves a product overview page and prepares for product detail pages. It demonstrates how to use Node.js to read files, serve HTML templates, and handle basic routing without any external frameworks.\n\n---\n\n## Features\n\n- **Static Data Handling**: Reads product data from a JSON file (\n\ndata.json\n\n) at the server startup.\n\n- **HTML Templating**: Dynamically replaces placeholders in HTML templates with product data.\n- **Basic Routing**: Serves different pages based on the URL path (`/overview`, `/product`, `/api`).\n- **Simple Server**: Uses Node.js's built-in\n\nhttp\n\nmodule to create a server.\n\n- **Beginner-Friendly Code**: Includes comments and alternative approaches for learning purposes.\n\n---\n\n## Project Structure\n\n```\nproject-folder/\n│\n├── dev-data/\n│   └── data.json                # JSON file containing product data\n│\n├── templates/\n│   ├── template-overview.html   # Template for the overview page\n│   ├── template-card.html       # Template for individual product cards\n│   └── template-product.html    # Template for product details (to be implemented)\n│\n├── index.js                     # Main Node.js server file\n└── README.md                    # Project documentation\n```\n\n---\n\n## How It Works\n\n1. **Data Loading**:\n\n   - The server reads the data.json\n   - file once at startup and parses it into a JavaScript object.\n\n2. **HTML Templating**:\n   - The replaceTemplate\n\nfunction replaces placeholders (e.g., `{%PRODUCTNAME%}`, `{%PRICE%}`) in the HTML templates with actual product data.\n\n3. **Routing**:\n   - `/overview`: Displays all products as cards using the `template-overview.html` and template-card.html.\n   - `/product`: Placeholder for product detail pages (to be implemented).\n   - `/api`: Returns the raw JSON data as an API response.\n   - Any other route: Returns a `404 Not Found` page.\n\n---\n\n## Setup and Usage\n\n### Prerequisites\n\n- Install [Node.js](https://nodejs.org/) on your machine.\n\n### Steps\n\n1. Clone or download this repository.\n2. Navigate to the project folder in your terminal.\n3. Run the server:\n   ```bash\n   node index.js\n   ```\n4. Open your browser and visit:\n\nhttp://127.0.0.1:8000/overview\nto see the product overview page.\nhttp://127.0.0.1:8000/api\nto see the raw JSON data.\n\n---\n\n## Example Data\n\nHere’s an example of the product data used in this project:\n\n```json\n[\n  {\n    \"id\": \"1\",\n    \"productName\": \"Organic Apple\",\n    \"image\": \"🍎\",\n    \"from\": \"Italy\",\n    \"nutrients\": \"Vitamins A, C\",\n    \"quantity\": \"1kg\",\n    \"price\": \"3.99\",\n    \"description\": \"Fresh organic apples.\",\n    \"organic\": true\n  },\n  {\n    \"id\": \"2\",\n    \"productName\": \"Banana\",\n    \"image\": \"🍌\",\n    \"from\": \"Ecuador\",\n    \"nutrients\": \"Potassium\",\n    \"quantity\": \"1kg\",\n    \"price\": \"2.49\",\n    \"description\": \"Sweet bananas.\",\n    \"organic\": false\n  }\n]\n```\n\n---\n\n## Learning Highlights\n\n- **File System**: Learn how to read and write files synchronously and asynchronously in Node.js.\n- **Routing**: Understand how to handle different URL paths using basic conditional logic.\n- **HTML Templating**: Practice replacing placeholders in HTML templates with dynamic data.\n- **Error Handling**: See examples of error handling in both synchronous and asynchronous file operations.\n- **Refactoring**: Explore alternative approaches (e.g., Promises, async/await) for better readability and maintainability.\n\n- **Product Details**: Implement the `/product` route to display detailed information about a single product.\n\n- **Templating Engines**: Experiment with templating engines like EJS, Pug, or Handlebars for more advanced templating.\n- **Dynamic Data**: Replace the static JSON file with a database (e.g., MongoDB, MySQL) for dynamic data handling.\n- **ES6 Modules** (coming soon): Transition the codebase to use modern JavaScript syntax and ES6 module structure for better scalability and maintainability.\n\n---\n\n**What’s new in feature/modules?**\n🔄 Code Refactoring: The index.js file has been cleaned up for better readability and maintainability.\n\n🧼 **Removed Comment Clutter:** Unnecessary or outdated comments were removed to streamline the learning experience.\n\n🧠 **Modular Functions:** Key features like templating, routing, and response handling have been broken into clear, concise modules.\n\n✨ **Improved Readability:** Cleaner variable and function names, organized file structure, and streamlined logic.\n\n📦 **ES6 Modules Transition (Planned):** Moving towards ES6 import/export syntax to embrace modern JavaScript standards.\n\nThis branch maintains educational clarity while introducing best practices for cleaner production-ready code.\n\n---\n\nIf you're curious to compare the beginner-friendly approach with a more refined modular structure, simply switch to the branch:\n\n```bash\ngit checkout feature/modules\n```\n\n## 🚧 Current Development: feature/npm\n\nThis branch introduces essential project setup improvements with `npm` and dev tools.\n\n### ✅ What's Done\n\n- Initialized `npm` and created a `package.json` file.\n- Installed [`slugify`](https://www.npmjs.com/package/slugify) for cleaner, URL-friendly strings (e.g., product slugs).\n- Installed `nodemon` as a **dev dependency** for hot reloading during development.\n- Created `.gitignore` to prevent `node_modules`, `.log` files, and other untracked files from being committed.\n\n### 💡 Why It Matters\n\n- **Modular Development**: Keeps project dependencies well-organized.\n- **Improved Dev Workflow**: `nodemon` auto-restarts the server on file changes.\n- **Clean Repository**: `.gitignore` avoids unnecessary clutter on GitHub.\n\n### 🛠 How to Use\n\nAfter cloning or switching to this branch, run:\n\n```bash\nnpm install\n```\n\n```bash\nnpm run dev\n```\n\nTry:\n\n```bash\ngit checkout main            # Basic CommonJS\ngit checkout feature/basic-nodeJs  # The building from line 1 with comments!\ngit checkout feature/modules # Modular CommonJS\ngit checkout feature/npm     # npm \u0026 dev tools setup\ngit checkout feature/es6     # You are here!\n```\n\n## Acknowledgments\n\nThis project was created as a learning exercise to understand the fundamentals of Node.js without relying on external frameworks — focusing purely on core concepts.\n\nBuilt by **Tuanthong Vaidyanond**\nThe foundational concepts and structure are based on the course by [Jonas Schmedtmann](https://jonas.io/).\n**Node.js, Express, MongoDB \u0026More**\n\n© Jonas Schmedtmann\nThis project is open for personal and commercial use, but not to be claimed as your own design.\nCrediting the original author is highly appreciated!\n\n---\n\n```\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftvatdci%2Fnode-farm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftvatdci%2Fnode-farm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftvatdci%2Fnode-farm/lists"}