Improved working directory switch.

Ylian Saint-Hilaire committed Jan 29, 2020 at 15:29 UTC 870ef4c279d3294150444252471e524a90ac239f
1 file changed +2 -3
meshcentral.js
+2 -3
@@ -2281,9 +2281,8 @@ function mainStart() {
2281 // Check the NodeJS is version 6 or better.
2282 if (Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 6) { console.log("MeshCentral requires Node v6 or above, current version is " + process.version + "."); return; }
2283
2284 - // If running within the node_modules folder, move working directory back to parent.
2285 - if (process.cwd().endsWith('\\node_modules\\meshcentral') || process.cwd().endsWith('/node_modules/meshcentral')) { process.chdir(require('path').join(process.cwd(), '..', '..')); }
2286 - if (process.cwd().endsWith('\\node_modules') || process.cwd().endsWith('/node_modules')) { process.chdir(require('path').join(process.cwd(), '..')); }
2284 + // If running within the node_modules folder, move working directory to the parent of the node_modules folder.
2285 + if (__dirname.endsWith('\\node_modules\\meshcentral') || __dirname.endsWith('/node_modules/meshcentral')) { process.chdir(require('path').join(__dirname, '..', '..')); }
2286
2287 // Check for any missing modules.
2288 InstallModules(['minimist'], function () {