forked from abrahamjuliot/creepjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
28 lines (24 loc) · 713 Bytes
/
Copy pathserver.js
File metadata and controls
28 lines (24 loc) · 713 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
const express = require('express')
const fs = require('fs')
const path = require('path')
const staticPath = path.join(__dirname, '/')
const app = express()
app.use(express.static(staticPath))
app.post('/', (req, res) => {
const { math: hash, ua: userAgent } = req.query
// read
fs.readFile('math.json', (err, file) => {
if (err) { throw err }
const data = JSON.parse(file)
const found = data.filter(item => item.id == hash)[0]
if (!found) {
data.push({ id: hash, userAgent }) // update
const json = JSON.stringify(data, null, 2)
fs.writeFile('math.json', json, err => {
if (err) { throw err }
console.log('file updated')
})
}
})
})
app.listen(3000, () => console.log('⚡'))