-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (27 loc) · 812 Bytes
/
index.js
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
32
33
import dotenv from 'dotenv';
import express from 'express';
import fs from 'fs';
const app = express();
dotenv.config();
if (!fs.existsSync("Files"))
fs.mkdirSync("Files");
const PORT = process.env.PORT;
app.get("/", (req, res) => {
res.send({message:"server running successfully"})
})
app.get("/createFiles", (req, res) => {
const date=new Date()
let fileName = date.toISOString();
fileName = fileName.slice(0, 19).replace(/:/g,"-");
let content = date.valueOf().toString();
fs.writeFile((`./Files/${fileName}.txt`), content, ((err) => {
if(err)
console.log(err)
}))
res.send({message:"File Created"})
})
app.get("/retreiveFiles", (req, res) => {
let directory = fs.readdirSync("./Files")
res.send(directory.sort())
})
app.listen(PORT,(()=>console.log(`server running successfully @${PORT}`)))