summaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..01003c4
--- /dev/null
+++ b/index.js
@@ -0,0 +1,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')
+})