This application helps users plan their trips by fetching relevant weather data and displaying images of the destination. The app utilizes multiple APIs to provide current and future weather forecasts based on the user's travel date and location.
This travel application accepts a location and departure date from the user and returns:
- Current Weather Forecast if the trip is within a week.
- Predicted Weather Forecast if the trip is in the future.
- Image of the travel destination.
- Fetches weather data using the Weatherbit API.
- Retrieves coordinates for the location from the Geonames API.
- Displays images of the travel destination using the Pixabay API.
- Purpose: Get latitude and longitude coordinates for a given location.
- API Docs: Geonames API Documentation
- Purpose: Get weather forecast data (current or predicted) based on coordinates.
- API Docs: Weatherbit API Documentation
- Purpose: Fetch an image of the travel destination based on the location name.
- API Docs: Pixabay API Documentation
- The user submits a location and a departure date via a simple form.
- The app sends the location to the Geonames API to retrieve the geographical coordinates (latitude and longitude).
- Based on the proximity of the departure date:
- If the trip is within 7 days, the app fetches the current weather forecast using the Weatherbit API.
- If the trip is more than 7 days away, it fetches the predicted forecast from the same API.
- The app sends the location name to the Pixabay API to retrieve an image of the destination.
- All this data (weather and image) is displayed to the user.
- Node.js v22 (for running JavaScript)
- API keys for Geonames, Weatherbit, and Pixabay (sign up on their respective websites to get these).
- Clone the repository:
git clone https://github.com/yourusername/travel-planner.git
- Install dependencies: npm install
- Set up environment variables: Create a .env file in the root directory. Add the following keys with your API information: GEONAMES_USERNAME=your_geonames_username WEATHERBIT_API_KEY=your_weatherbit_api_key PIXABAY_API_KEY=your_pixabay_api_key
- Run the application: npm start
This project uses Jest and Supertest to ensure that the Express server works correctly. Follow the steps below to set up and run the tests.
-
Install Jest and Supertest
You need to install Jest and Supertest in your project. Run the following command in your terminal:
npm install --save-dev jest supertest
-
Run the Test Command Run the tests using the following command in your terminal: npm test