Created
February 2, 2017 09:15
-
-
Save maxfunke/63bb9c161adfb8597437f4dfe17af2db to your computer and use it in GitHub Desktop.
Handling paths for different OS in Node.js - '/' or '\'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const FS = require('fs'); | |
const OS = require('os'); | |
let EXEC_PATH = process.argv[1]; | |
let FILE_PATH = getFilePath(EXEC_PATH); | |
const FILE = JSON.parse(FS.readFileSync(FILE_PATH + '/myFile.json', 'utf8')); | |
function getFilePath(execPath){ | |
let splitter = (OS.type() === "Windows_NT") ? "\\" : "/"; | |
let path = execPath.split(splitter); | |
path.pop(); | |
return (path.join(splitter)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment