I'm trying out Node.js for scripting.
I have a script, where I check the existence of ./node_modules/some-package
. If it doesn't exist, some-package
is installed.
This seems kind of hacky however.
Is there a better way to check if a particular package is installed from within the script?
sample code
const fs = require('fs');
let installed;
try {
fs.accessSync('./node_modules/.bin/some-package');
installed = true;
} catch (err) {
installed = false;
}