The NewsRead Server is the backend service powering the NewsRead application. It is designed to handle news fetching, storage, and text-to-speech (TTS) functionality. This server interacts with the newsdata.io API for fetching news articles and leverages AWS Polly for generating audio files, ensuring a seamless and efficient experience for the user.
This server is essential for running the NewsRead application. To view the client-side code and integrate it with this backend, refer to the newsread repository.
- News Management:
- Fetch and store the latest news articles.
- Retrieve trending, latest, or specific articles.
- Database Optimization:
- Reduce API calls by efficiently storing fetched data in PostgreSQL.
- Text-to-Speech (TTS):
- Convert articles into audio using AWS Polly and stream it to users.
- Trending Analytics:
- Track and update article visits for ranking popular articles.
- Node.js and npm installed.
- Setup AWS Polly and AWS S3 enabled with appropriate access keys.
-
Clone the Repository:
git clone https://github.com/anujgawde/newsread-server cd newsread-server
-
Install Dependencies:
npm install
-
Set Environment Variables:
Create a.env
file in the root directory and configure the following variables:AWS_SECRET_ACCESS_KEY=your_aws_secret_access_key AWS_TTS_BUCKET_NAME=your_aws_s3_bucket_name DB_URL=your_postgresql_connection_url DB_NAME=your_database_name DB_PASSWORD=your_database_password NEWSDATA_API_KEY=your_newsdata_api_key
-
Run the Server:
npm run start:dev
-
Test the API:
The server runs athttp://localhost:8001
. Use tools like Postman or your browser to test endpoints.
GET /articles/get-all-articles
: Retrieve all stored articlesGET /articles/get-latest-articles
: Fetch and store the latest articlesGET /articles/get-trending-articles
: Retrieve trending articles based on visitsGET /articles/:id
: Retrieve a specific article by its IDPOST /articles/read-article
: Convert article content to audio and play itPOST /articles/update-article-visits
: Increment the visit count for an article
- Backend Framework: NestJS
- Database:
- Cloud Services:
- News API: newsdata.io
- Add API caching to reduce database queries.
- Implement multi-language TTS support.
- Enhance analytics for article performance.
Contributions are welcome! Please open an issue or submit a pull request for suggestions or improvements.
- Author - Anuj Gawde