{"size": 713, "ext": "js", "max_stars_repo_path": "session4/app.js", "max_stars_repo_name": "andreeavata2/NODEJS-FIIPRACTIC", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "session4/app.js", "max_issues_repo_name": "andreeavata2/NODEJS-FIIPRACTIC", "max_issues_repo_issues_event_min_datetime": "2021-05-11T12:42:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-11T12:42:00.000Z", "max_forks_repo_path": "session4/app.js", "max_forks_repo_name": "andreeavata2/NODEJS-FIIPRACTIC", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 20.3714285714, "max_line_length": 58, "alphanum_fraction": 0.4530154278}
const express = require("express");
const fs = require("fs");

const app = express();

app.post('/', (req, res) => {
    let file = ''

    req.on('data', data => {
        file += data.toString();
    });

    req.on("end", () => {
        file = file
            .split("\r\n")
            .filter((el) => el)
            .slice(1,-1);
        
        const metadata = file[0];

        file = file.slice(2)[0];

        console.log(file);

        const filename = metadata
            .match(/filename=\"[A-Za-z.]+\"/g)[0]
            .split('"')[1];
        console.log(filename);

        fs.writeFileSync(`new-${filename}`, file);        
    })
})

app.listen(3000, () => console.log("server started"));
