Last active
July 4, 2024 16:50
-
-
Save frontsideair/60cb2e51e32d7a6d0d4ec0e26e57e20a to your computer and use it in GitHub Desktop.
Use npx to require packages without installing, proof-of-concept
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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