A workshop showing making your own `npx`-runnable npm package. 🎁
MIT License
A workshop showing making your own npx
-runnable npm package. 🎁
We'll cover:
https://www.npmjs.com/package/vc-npm-resume
index.js
fileconsole.log
to that filenode index.js
: it runs!
node --watch index.js
: it runs in watch modenpm init
bin: "index.js"
name
#!/usr/bin/env node
("hashbang comment) to the top of index.js
npm login
npm whoami
npm publish
npx vc-npm-resume@latest
npm version patch
package.json
index.js
npm install chalk
node_modules
to gitignore
"type": "module"
to package.json
import chalk from "chalk"
npm install strip-ansi
stripAnsi
in index.js
to ease line length computations with chalk403
Error in npm publish
Change the name in your package.json
.
You cannot publish over the previously published versions
Try changing the version in package.json
.
Otherwise, try npm login
to make sure you're logged in.
Add a bin
entry in package.json
.
And don't feel to bad about it, I totally forgot during the workshop 😉.
Either:
"type": "module"
to your package.json
.mjs
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
Switch from CJS (require
) to ESM (import
)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules