-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (27 loc) · 764 Bytes
/
index.js
File metadata and controls
31 lines (27 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import express from 'express'
import fs from 'fs/promises'
import cors from 'cors'
const app = express()
app.use(cors())
const PORT = process.env.PORT || 3000
const jsonFilePath = './techstack_names.json'
async function readJsonFile() {
try {
const jsonData = await fs.readFile(jsonFilePath, 'utf-8')
return JSON.parse(jsonData)
} catch (error) {
console.error('Error reading JSON file:', error.message)
return null
}
}
app.get('/api/techstacks', async (req, res) => {
const techstackNames = await readJsonFile()
if (techstackNames) {
res.json(techstackNames)
} else {
res.status(500).json({ error: 'Internal Server Error' })
}
})
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`)
})