UNPKG

detect-features

Version:

Detect and report browser and hardware features.

44 lines (34 loc) 1.04 kB
// @ts-check // Native const fs = require('fs'); const path = require('path'); // Vendor const express = require('express'); const bodyParser = require('body-parser'); const app = express(); const port = 3000; app.use('/build', express.static(path.join(`${__dirname}/build/`))); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); app.get('/', (req, res) => { res.sendFile(path.join(`${__dirname}/index.html`)); }); app.post('/result', (req, res) => { const date = new Date(); const formattedDate = `${[date.getDate(), date.getMonth() + 1, date.getFullYear()].join('-')}_${[ date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds(), ].join('-')}`; fs.writeFile(`./logs/${formattedDate}.json`, JSON.stringify(req.body), (error) => { if (error) { console.error(error); } else { console.log(`Saved file: ./logs/${formattedDate}.json`); } }); res.send(req.body); }); app.listen(port); console.log(`Server started on port ${port}`);