summaryrefslogtreecommitdiff
path: root/index.js
blob: 01003c431764db025570b50c87bad9240a7cccc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import express from 'express'
import axios from 'axios'

const app = express()

app.get('/posts', async(req, res) => {
  try {
    const result = await axios.get('https://jsonplaceholder.typicode.com/posts')
    res.json(result.data)
  } catch (error) {
    res.status(500).json({ error: 'Fetch failed.'})
  }
})

app.listen(3000, () => {
  console.log('Server running at port 3000')
})