Skip to content
 
 

Repository files navigation

project

application assignment PROJECT OVERVIEW This project is a simple Node.js web application that fetches data from an external API and displays it on a Bootstrap 5-styled webpage. The application demonstrates the use of core Node.js features like creating a web server, handling asynchronous API requests, and modularizing code. Additionally, the frontend is styled using Bootstrap 5 for responsive design and layout. The project architecture is simple, focusing on clean separation of concerns using modularized JavaScript files for handling server logic, API requests, and custom events.

Directory Structure: node_modules/: Contains all the installed Node.js packages, including axios and other dependencies installed via npm. views/: Contains the HTML files used for rendering the frontend of the application. Includes: index.html: The main HTML file for the webpage, styled using Bootstrap 5. public/: Holds the static assets like JavaScript and CSS files. script.js: Frontend JavaScript to fetch and display API data dynamically. bootstrap/: Bootstrap 5 CSS files. nodejs_info.json: A JSON file containing metadata about the Node.js project (e.g., Node.js version, application information). index.js: The main entry point for the Node.js server. It initializes the server, routes requests, and handles API calls. requestHandler.js: A module that handles incoming HTTP requests to serve HTML pages and API responses. events.js: Contains custom event handling logic using Node.js's EventEmitter module. package.json: Project's configuration file for npm, which includes dependencies, scripts, and metadata. Table of Topics and Descriptions Topic Description Project Overview A simple Node.js application that fetches and displays API data in a Bootstrap-styled webpage. Node.js The JavaScript runtime environment used to build the web server and handle backend logic. npm Node Package Manager, used to install dependencies like axios for API requests. Bootstrap 5 A popular CSS framework used for responsive and clean styling of the webpage. HTTP Module Core Node.js module used to create the web server and listen to incoming HTTP requests. axios A promise-based HTTP client used for fetching data from an external API (JSONPlaceholder). Asynchronous Programming The use of async/await to handle non-blocking API requests for improved performance. Custom Event Emitter Implementation of an event-driven architecture in Node.js using the EventEmitter class. Views Directory Holds the HTML files, primarily index.html, which is styled using Bootstrap 5. Public Directory Contains static assets like Bootstrap CSS and JavaScript files (e.g., script.js). API Integration The application fetches posts from the JSONPlaceholder API and dynamically displays them. Modularization Code is split into modules for request handling (requestHandler.js) and event logic (events.js). Server-Side Logic The backend logic is implemented in index.js, which initializes the server and handles routes. Error Handling Graceful error handling is implemented to ensure the app responds correctly when issues occur. Git Version Control The project is managed using Git, with a full history of commits pushed to GitHub.

Here's a detailed table with topics and corresponding descriptions that you can include in your README file, along with a project overview and directory structure description:

Project Overview This project is a simple Node.js web application that fetches data from an external API and displays it on a Bootstrap 5-styled webpage. The application demonstrates the use of core Node.js features like creating a web server, handling asynchronous API requests, and modularizing code. Additionally, the frontend is styled using Bootstrap 5 for responsive design and layout. The project architecture is simple, focusing on clean separation of concerns using modularized JavaScript files for handling server logic, API requests, and custom events.

Directory Structure: node_modules/: Contains all the installed Node.js packages, including axios and other dependencies installed via npm. views/: Contains the HTML files used for rendering the frontend of the application. Includes: index.html: The main HTML file for the webpage, styled using Bootstrap 5. public/: Holds the static assets like JavaScript and CSS files. script.js: Frontend JavaScript to fetch and display API data dynamically. bootstrap/: Bootstrap 5 CSS files. nodejs_info.json: A JSON file containing metadata about the Node.js project (e.g., Node.js version, application information). index.js: The main entry point for the Node.js server. It initializes the server, routes requests, and handles API calls. requestHandler.js: A module that handles incoming HTTP requests to serve HTML pages and API responses. events.js: Contains custom event handling logic using Node.js's EventEmitter module. package.json: Project's configuration file for npm, which includes dependencies, scripts, and metadata. Table of Topics and Descriptions Topic Description Project Overview A simple Node.js application that fetches and displays API data in a Bootstrap-styled webpage. Node.js The JavaScript runtime environment used to build the web server and handle backend logic. npm Node Package Manager, used to install dependencies like axios for API requests. Bootstrap 5 A popular CSS framework used for responsive and clean styling of the webpage. HTTP Module Core Node.js module used to create the web server and listen to incoming HTTP requests. axios A promise-based HTTP client used for fetching data from an external API (JSONPlaceholder). Asynchronous Programming The use of async/await to handle non-blocking API requests for improved performance. Custom Event Emitter Implementation of an event-driven architecture in Node.js using the EventEmitter class. Views Directory Holds the HTML files, primarily index.html, which is styled using Bootstrap 5. Public Directory Contains static assets like Bootstrap CSS and JavaScript files (e.g., script.js). API Integration The application fetches posts from the JSONPlaceholder API and dynamically displays them. Modularization Code is split into modules for request handling (requestHandler.js) and event logic (events.js). Server-Side Logic The backend logic is implemented in index.js, which initializes the server and handles routes. Error Handling Graceful error handling is implemented to ensure the app responds correctly when issues occur. Git Version Control The project is managed using Git, with a full history of commits pushed to GitHub. Project Structure Here's a detailed look at the file structure of the project:

graphql Copy code project-root/ ├── node_modules/ # Installed npm packages ├── public/ # Static files (JS, CSS) │ ├── bootstrap/ # Bootstrap CSS files │ └── script.js # Frontend JavaScript to handle dynamic API data loading ├── views/ # HTML templates │ └── index.html # Main webpage file using Bootstrap 5 ├── nodejs_info.json # Project metadata (Node.js version, app info) ├── package.json # npm dependencies, scripts, and project metadata ├── index.js # Entry point, starts the server and handles requests ├── requestHandler.js # Handles incoming requests, serves HTML and API data ├── events.js # Event-driven architecture with custom event emitters └── README.md # Project documentation Key Files: index.js:

Creates the HTTP server using the built-in http module. Handles two routes: /: Serves the static HTML file (index.html). /api/data: Fetches external data from the JSONPlaceholder API using axios and returns it as JSON. Implements custom events to log when requests are received. requestHandler.js:

Module for separating the request handling logic. Responds with the index.html file or serves API data. events.js:

Uses the EventEmitter class to create custom events. Emits a "requestReceived" event every time the server gets a request. nodejs_info.json:

A JSON file that stores information about the Node.js environment, such as Node.js version and application details. script.js:

Client-side JavaScript that fetches data from the /api/data endpoint and renders it dynamically on the webpage.

BRIEF SUMMARY Installing Node.js and Setup In this lesson, I learned how to install Node.js and initialize a project using npm. I also created a GitHub repository to manage the project versioning, ensuring proper tracking of changes.

Lesson : Server-Side JavaScript I created a basic JavaScript file and ran it with Node.js, which demonstrated the ability to execute JavaScript outside the browser. This simple step helped confirm the proper installation and setup of the environment.

Lesson : Building a Simple Web Server Using Node.js's built-in http module, I created a basic web server that listens on port 3000 and returns a "Hello, World!" message. This is the first real example of how Node.js can be used to handle HTTP requests.

Lesson : Understanding Modules in Node.js I learned how to organize code by breaking it into smaller modules. The server request handler was refactored into a separate module, making the code more maintainable and reusable.

Lesson : Node Package Manager (npm) In this lesson, I explored the npm ecosystem by installing the axios package to make HTTP requests to external APIs. This is crucial for integrating third-party services into Node.js applications.

Lesson : Asynchronous Programming in Node.js I refactored the API call using async/await, which allowed me to handle asynchronous operations more cleanly. This pattern is key in Node.js for managing I/O-heavy operations like fetching external data.

Lesson : Event-driven Architecture in Node.js Node.js is event-driven, and in this lesson, I implemented a custom event emitter to log messages when the server receives requests. This demonstrated how event-driven programming works, a core feature of Node.js.

Lesson : Building a Complete Node.js Application This final lesson combined everything learned into a complete Node.js app. The app starts a web server, fetches data from an API, and displays it in a Bootstrap-styled layout. The app also handles errors and makes use of events, external modules, and async programming.

About

application assignment

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages