vc-npm-resume
v0.1.0
Published
A workshop showing making your own `npx`-runnable npm package. ๐
Downloads
3
Readme
Virtual Coffee npm Resume
A workshop showing making your own npx
-runnable npm package. ๐
We'll cover:
- (topic: node/npm) How to set up a very straightforward npm package (just a single .js file)
- (topic: core JS) Logging some things in the file
- (topic: node/npm) Adding a dependency on chalk to get nice colors
- (topic: core JS) Wrapping those logs with | etc. characters to make a table
- (delighter) Using arbitrary math to make a gradient with chalk
https://www.npmjs.com/package/vc-npm-resume
Steps we took
- Create an
index.js
file - Add a
console.log
to that file node index.js
: it runs!node --watch index.js
: it runs in watch mode
npm init
- Add a
bin: "index.js"
- If you're not Josh, change the
name
- Add a
- Add
#!/usr/bin/env node
("hashbang comment) to the top ofindex.js
- Make an npm account (https://www.npmjs.com/signup)
npm login
- Verify with
npm whoami
- Verify with
npm publish
npx vc-npm-resume@latest
- Make some changes to the file
npm version patch
- This creates a Git commit with a tag
- This updates your
package.json
- Fancify the table in
index.js
npm install chalk
- Add
node_modules
togitignore
- Add
"type": "module"
topackage.json
- Add
import chalk from "chalk"
- Fun fact: "ANSI Escape codes" is what they're called
- https://stackoverflow.com/questions/4842424/list-of-ansi-color-escape-sequences
npm install strip-ansi
- Use
stripAnsi
inindex.js
to ease line length computations with chalk
Debugging
403
Error in npm publish
You do not have permission to publish "vc-npm-resume". Are you logged in as the correct user?
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.
npm ERR! could not determine executable to run
Add a bin
entry in package.json
.
And don't feel to bad about it, I totally forgot during the workshop ๐.
Cannot use import statement outside a module
Either:
- Add
"type": "module"
to yourpackage.json
- Rename the file to
.mjs
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
Error [ERR_REQUIRE_ESM]: require() of ES Module...
Switch from CJS (require
) to ESM (import
)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules