Skip to content

Commit

Permalink
Update server.js
Browse files Browse the repository at this point in the history
Add GET for news from NewsAPI API.
  • Loading branch information
JancoEngelbrecht committed Sep 7, 2024
1 parent a3dc046 commit 3dce32e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const express = require('express');
const cors = require('cors');
const app = express();
const axios = require('axios');

// Use the port assigned by Azure, or default to 3000 locally
const port = process.env.PORT || 3000;
Expand All @@ -16,6 +17,21 @@ app.get('/', (req, res) => {
res.json("janco");
});

//Get news from NewsAPI
app.get('/news', async (req, res) => {
try {
const response = await axios.get('https://newsapi.org/v2/top-headlines', {
params: {
country: 'us',
apiKey: 'a5c9c48cee5b4d81b4492fa66bf61661'
}
});
res.json(response.data);
} catch (error) {
res.status(500).json({ error: 'Error fetching news data' });
}
});

// Route to get weather data
app.get('/weather', (req, res) => {
const data = {
Expand Down

0 comments on commit 3dce32e

Please sign in to comment.