A simple Express.js server that aggregates data from multiple public APIs and provides RESTful endpoints for retrieving combined information.
- Fetches data from three external APIs in parallel:
- Random cat facts from Cat Fact API
- Random dog images from Dog CEO API
- Random jokes from Official Joke API
- Provides a combined data endpoint
- Includes a counter endpoint for metrics tracking
- Node.js (v14 or higher recommended)
- npm (comes with Node.js)
-
Clone or download this project
git clone https://github.com/LuffySama-Dev/SampleNodejsExample.git
-
Install dependencies:
npm install
Run the following command to start the server:
node index.jsThe server will start on http://localhost:5555 by default (or the port specified in the PORT environment variable).
Returns combined data from all three external APIs.
Example Request:
curl http://localhost:5555/dataExample 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!"
}Increments a counter for metrics tracking.
Example Request:
curl http://localhost:5555/addCountExample Response:
{
"method": "GET",
"message": "Increased count by 1."
}PORT- Server port (default: 5555)
To use a custom port:
PORT=3000 node index.js- express (^5.2.0) - Web framework for Node.js
- axios (^1.13.2) - Promise-based HTTP client
If any of the external APIs fail to respond, the /data endpoint will return:
{
"error": "Failed to fetch data from APIs"
}This project is open source and available under the MIT License.