How can I run a nodejs script which require other 3rd-party node modules, without having to install the external module beforehand and without having to setup package.json / package-lock.json files?
e.x. I was trying to achieve this with npx, but couldn't make it work.
npx -p lodash -c "node test.js"
content of test.js:
const _ = require('lodash') console.log(_.constant(1))
I know I can do npm i lodash or npm i -g lodash first and then run the script, but my question is different ??
npm i lodash
npm i -g lodash
2.1m questions
2.1m answers
60 comments
57.0k users