From 9b239893f718cc8b89989e8555f064b383a1bdac Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Wed, 29 Jan 2020 15:29:15 -0800 Subject: [PATCH] Improved working directory switch. --- meshcentral.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/meshcentral.js b/meshcentral.js index a8b2618c..9df12d0f 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -2281,9 +2281,8 @@ function mainStart() { // Check the NodeJS is version 6 or better. if (Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 6) { console.log("MeshCentral requires Node v6 or above, current version is " + process.version + "."); return; } - // If running within the node_modules folder, move working directory back to parent. - if (process.cwd().endsWith('\\node_modules\\meshcentral') || process.cwd().endsWith('/node_modules/meshcentral')) { process.chdir(require('path').join(process.cwd(), '..', '..')); } - if (process.cwd().endsWith('\\node_modules') || process.cwd().endsWith('/node_modules')) { process.chdir(require('path').join(process.cwd(), '..')); } + // If running within the node_modules folder, move working directory to the parent of the node_modules folder. + if (__dirname.endsWith('\\node_modules\\meshcentral') || __dirname.endsWith('/node_modules/meshcentral')) { process.chdir(require('path').join(__dirname, '..', '..')); } // Check for any missing modules. InstallModules(['minimist'], function () {