Skip to content

Commit 49bc725

Browse files
authored
exit if node version too low (#226)
1 parent 49062b5 commit 49bc725

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packages/cli-repl/src/cli-repl.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import util from 'util';
2525
import read from 'read';
2626
import os from 'os';
2727
import fs from 'fs';
28+
import semver from 'semver';
2829

2930
/**
3031
* Connecting text key.
@@ -50,6 +51,7 @@ class CliRepl {
5051
* Instantiate the new CLI Repl.
5152
*/
5253
constructor(driverUri: string, driverOptions: NodeOptions, options: CliOptions) {
54+
this.verifyNodeVersion();
5355
this.options = options;
5456
this.mongoshDir = path.join(os.homedir(), '.mongodb/mongosh/');
5557
this.lineByLineInput = new LineByLineInput(process.stdin);
@@ -307,6 +309,14 @@ class CliRepl {
307309
return formatOutput(result);
308310
};
309311

312+
verifyNodeVersion(): void {
313+
const { engines } = require('../package.json');
314+
if (!semver.satisfies(process.version, engines.node)) {
315+
console.log(`WARNING: mismatched node version. Minimum node version required ${engines.node}. Currently using ${process.version}. Exiting...\n\n`);
316+
process.exit(1);
317+
}
318+
}
319+
310320
/**
311321
* The greeting for the shell.
312322
*/

0 commit comments

Comments
 (0)