Skip to content

Instantly share code, notes, and snippets.

@omar2205
Created October 31, 2019 11:46
Show Gist options
  • Save omar2205/1f2178b57ff7b9edd857d17e1af3db53 to your computer and use it in GitHub Desktop.
Save omar2205/1f2178b57ff7b9edd857d17e1af3db53 to your computer and use it in GitHub Desktop.
express async fetch
const app = require('express')()
const fetch = require('node-fetch')
const API_KEY = process.env.API_KEY
app.get('/posts', async (req, res) => {
const getPosts = () => fetch(`/api/key=${API_KEY}`)
const processPosts = async () => {
const posts = await getPosts()
const postsJSON = await posts.json()
res.end(JSON.stringify(postsJSON)
}
processPosts()
})
app.listen(process.env.PORT || 8080, () => console.log('server is online'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment