This Node.js application serves as a simple API to fetch climate change news articles from various online newspapers.
The application uses express
for setting up the server, axios
for HTTP requests, and cheerio
for parsing HTML content.
The API scrapes specified news websites for articles containing the keyword "climate" and presents these articles in a JSON format.
- Fetches and displays a list of climate change related news articles.
- Allows filtering news articles by specific newspaper sources.
- Dynamically constructs article URLs from relative paths using base URLs.
Before installation, ensure you have Node.js and npm installed on your system.
- Clone the repository:
git clone [repository-url]
- Navigate to the project directory:
cd [project-directory]
- Install dependencies:
npm install
node -v
npm init
npm i cheerio
npm i express
npm i axios
npm i nodemon
npm run start
Start the server with the following command:
npm run start
The server runs on localhost
with the default port 8000
(configurable through environment variables).
-
Homepage (
/
):- Returns a welcome message.
- Method:
GET
-
All News (
/news
):- Returns a JSON object with an array of all collected climate change news articles.
- Method:
GET
-
News by Newspaper (
/news/:newspaperId
):- Replace
:newspaperId
with the desired newspaper's name to get articles specifically from that source. - Method:
GET
- Replace
- CityAM
- The Times
- The Guardian
- The Telegraph
- New York Times
- Los Angeles Times
- Sydney Morning Herald
- BBC
- Evening Standard
- The Sun
- Daily Mail
- New York Post
- NASA
- CNN
- CBS News
- USA Today
- ABC News
The newspapers
array in index.js
contains the configuration for each newspaper source, including the name, base URL, and specific climate change section URL.
- The link for 'UN News' is currently commented out due to issues causing API crashes.
This project is licensed under the MIT License.
This API is for educational purposes only. The scraping functionality might be against the terms of service of the news websites. Always ensure compliance with legal guidelines and website terms when scraping data.