I have a node app that I just started working with and each time I try to run it, it says there is a missing module. I\'ve just been using npm install ... for each
I have written a script for this.
Place it at the start of your script, and any uninstalled modules will be installed when you run it.
(function () {
var r = require
require = function (n) {
try {
return r(n)
} catch (e) {
console.log(`Module "${n}" was not found and will be installed`)
r('child_process').exec(`npm i ${n}`, function (err, body) {
if (err) {
console.log(`Module "${n}" could not be installed. Try again or install manually`)
console.log(body)
exit(1)
} else {
console.log(`Module "${n}" was installed. Will try to require again`)
try{
return r(n)
} catch (e) {
console.log(`Module "${n}" could not be required. Please restart the app`)
console.log(e)
exit(1)
}
}
})
}
}
})()