Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

javascript - Run single nodejs script which require 3rd party modules, without presetting package.json/package-lock.json. (npx?)

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 ??

question from:https://stackoverflow.com/questions/66055663/run-single-nodejs-script-which-require-3rd-party-modules-without-presetting-pac

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...