Make persistent storage location a constant
This commit is contained in:
parent
466dd184b1
commit
d68d780951
|
@ -4,13 +4,11 @@ import http from "http";
|
|||
import dotenv from "dotenv";
|
||||
import { Review, reviewSchema } from "./types";
|
||||
import { checkFile } from "./utils";
|
||||
import { dir } from "./utils";
|
||||
dotenv.config();
|
||||
|
||||
const origin = chalk.bold(chalk.yellow("main.js: "));
|
||||
const port = +process.env.PORT ?? 8080;
|
||||
const contentType = { "Content-Type": "application/json" };
|
||||
const fileName = dir + "data.json";
|
||||
|
||||
http
|
||||
.createServer((req, res) => {
|
||||
|
@ -37,7 +35,10 @@ http
|
|||
);
|
||||
|
||||
data.push(valid);
|
||||
fs.writeFileSync(fileName, JSON.stringify(data, null, 2));
|
||||
fs.writeFileSync(
|
||||
"./persist/data.json",
|
||||
JSON.stringify(data, null, 2),
|
||||
);
|
||||
|
||||
res.writeHead(200, contentType);
|
||||
res.write("OK");
|
||||
|
|
|
@ -13,15 +13,21 @@ export class Logger {
|
|||
}
|
||||
|
||||
log(text: any, args?: any): void {
|
||||
args ? console.log(this._main + text, args) : console.log(this._main + text);
|
||||
args
|
||||
? console.log(this._main + text, args)
|
||||
: console.log(this._main + text);
|
||||
}
|
||||
|
||||
warn(text: any, args?: any): void {
|
||||
args ? console.warn(this._wrn + this._main + text, args) : console.warn(this._wrn + this._main + text);
|
||||
args
|
||||
? console.warn(this._wrn + this._main + text, args)
|
||||
: console.warn(this._wrn + this._main + text);
|
||||
}
|
||||
|
||||
error(text: any, args?: any): void {
|
||||
args ? console.error(this._err + this._main + text, args) : console.error(this._err + this._main + text);
|
||||
args
|
||||
? console.error(this._err + this._main + text, args)
|
||||
: console.error(this._err + this._main + text);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import fs from "fs";
|
||||
import { Review } from "../types";
|
||||
|
||||
export const dir = "./persist/";
|
||||
|
||||
export function checkFile(file: string, encoding: fs.EncodingOption): Review[] {
|
||||
const dir = "./persist/";
|
||||
const fullPath = dir + file;
|
||||
let final: Review[];
|
||||
|
||||
|
|
Loading…
Reference in a new issue