Skip to content

Instantly share code, notes, and snippets.

@frontsideair
Last active October 22, 2020 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frontsideair/60cb2e51e32d7a6d0d4ec0e26e57e20a to your computer and use it in GitHub Desktop.
Save frontsideair/60cb2e51e32d7a6d0d4ec0e26e57e20a to your computer and use it in GitHub Desktop.
Use npx to require packages without installing, proof-of-concept
#!/usr/bin/env node
const npx = require('libnpx')
const path = require('path')
const packageName = "figlet"
const NPM_PATH = path.join(__dirname, 'node_modules', 'npm', 'bin', 'npm-cli.js')
npx._ensurePackages(packageName, { npm: NPM_PATH })
.then(results => {
const package = require(path.join(results.prefix, 'lib', 'node_modules', packageName))
package('hello', (err, data) => console.log(data))
})
.catch(error => console.error(error))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment