8000 Clean: Create util for getting dirname · PrashanthaTP/leetcode-client@1d72b9d · GitHub
[go: up one dir, main page]

Skip to content

Commit 1d72b9d

Browse files
committed
Clean: Create util for getting dirname
1 parent 27ad07a commit 1d72b9d

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

config/config.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import { readFileSync } from "fs";
22
import path from "path";
3-
import { fileURLToPath } from "url";
4-
5-
//Node.js 10 supports ECMAScript modules, where __dirname and __filename are no longer available.
6-
//https://stackoverflow.com/a/50053801/12988588
7-
//https://stackoverflow.com/a/55859500/12988588
8-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
3+
import { getDirname } from "../utils";
94

5+
const __dirname = getDirname(import.meta.url)
106
const configFilePath = path.resolve(__dirname, "../.env.json");
117
const configDataRaw = readFileSync(configFilePath);
128
const config = JSON.parse( configDataRaw );

utils/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import path from "path";
2+
import { fileURLToPath } from "url";
3+
4+
//Node.js 10 supports ECMAScript modules, where __dirname and __filename are no longer available.
5+
//https://stackoverflow.com/a/50053801/12988588
6+
//https://stackoverflow.com/a/55859500/12988588
7+
export const getDirname = ( filepath ) => {
8+
return path.dirname(fileURLToPath(import.meta.url));
9+
}
10+

0 commit comments

Comments
 (0)
0