Skip to content

Instantly share code, notes, and snippets.

@ZakiMohammed
Created February 6, 2022 20:26
Show Gist options
  • Save ZakiMohammed/5ea7bc4aaa6b82b80652f0d647d8ce07 to your computer and use it in GitHub Desktop.
Save ZakiMohammed/5ea7bc4aaa6b82b80652f0d647d8ce07 to your computer and use it in GitHub Desktop.
News API
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