Skip to content

LuffySama-Dev/SampleNodejsExample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SampleNodejsExample

A simple Express.js server that aggregates data from multiple public APIs and provides RESTful endpoints for retrieving combined information.

Features

  • Fetches data from three external APIs in parallel:
  • Provides a combined data endpoint
  • Includes a counter endpoint for metrics tracking

Prerequisites

  • Node.js (v14 or higher recommended)
  • npm (comes with Node.js)

Installation

  1. Clone or download this project

    git clone https://github.com/LuffySama-Dev/SampleNodejsExample.git
  2. Install dependencies:

    npm install

Usage

Start the Server

Run the following command to start the server:

node index.js

The server will start on http://localhost:5555 by default (or the port specified in the PORT environment variable).

Available Endpoints

GET /data

Returns combined data from all three external APIs.

Example Request:

curl http://localhost:5555/data

Example Response:

{
	"catFact": "Cats have 32 muscles in each ear.",
	"dogImage": "https://images.dog.ceo/breeds/hound-afghan/n02088094_1003.jpg",
	"joke": "Why did the scarecrow win an award? - Because he was outstanding in his field!"
}

GET /addCount

Increments a counter for metrics tracking.

Example Request:

curl http://localhost:5555/addCount

Example Response:

{
	"method": "GET",
	"message": "Increased count by 1."
}

Environment Variables

  • PORT - Server port (default: 5555)

To use a custom port:

PORT=3000 node index.js

Dependencies

  • express (^5.2.0) - Web framework for Node.js
  • axios (^1.13.2) - Promise-based HTTP client

Error Handling

If any of the external APIs fail to respond, the /data endpoint will return:

{
	"error": "Failed to fetch data from APIs"
}

License

This project is open source and available under the MIT License.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published