Created
February 6, 2022 20:26
-
-
Save ZakiMohammed/5ea7bc4aaa6b82b80652f0d647d8ce07 to your computer and use it in GitHub Desktop.
News API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const axios = require('axios').default | |
const app = express() | |
const PORT = process.env.PORT || 3000 | |
const URL = 'https://newsapi.org/v2/everything?q=sports&from=2022-01-06&sortBy=publishedAt&apiKey=01f06835c0af4e88ab9dd1c5988ae24f' | |
app.get('/', (req, res) => { | |
axios.get(URL) | |
.then(response => { | |
console.log(response.data); | |
res.json(response.data) | |
}) | |
.catch(error => { | |
console.log(error); | |
res.json(error) | |
}) | |
}) | |
app.listen(PORT, () => console.log(`Server started on port ${PORT}`)) | |
// npm i express axios |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment