1.9 KiB
1.9 KiB
Tavily Comparative Review Utility
This project provides a simple Node.js utility to fetch a comparative review of three entities using the Tavily API.
Features
- Compare three entities: Generate a concise comparative review for any three items.
- Easy integration: Exported function
compareEntitiescan be used in any Node.js project. - Environment‑based configuration: API key is loaded from a
.envfile. - Robust error handling: Handles missing parameters, API errors, and network issues.
Prerequisites
- Node.js v18 or newer
- A Tavily API key. Sign up at https://tavily.com to obtain one.
Setup
-
Clone the repository
git clone https://git.brojs.ru/kuzakhmetovartur/povtornyy-ekzamen-2-sravnitelnyy-obzor-3.git cd povtornyy-ekzamen-2-sravnitelnyy-obzor-3 -
Install dependencies
npm install -
Configure environment variables
Copy the example file and set your API key:
cp .env.example .env # Edit .env and replace YOUR_TAVILY_API_KEY_HERE with your actual key
Usage
const { compareEntities } = require('./src/index');
(async () => {
try {
const result = await compareEntities('Apple', 'Samsung', 'Google');
console.log(JSON.stringify(result, null, 2));
} catch (err) {
console.error('Error:', err.message);
}
})();
Run the script:
node src/index.js
Testing
The project uses Jest for unit tests.
npm test
Project Structure
├── src
│ └── index.js # Main utility
├── tests
│ └── compare.test.js # Unit tests
├── .env.example # Environment variable template
├── .gitignore
├── package.json
└── README.md
License
MIT © Your Name
Feel free to open issues or pull requests if you encounter any problems or have suggestions for improvement.