Publish to npm
1. Create an account on npm
Create an account here: https://www.npmjs.com/signup
Verify your email and setup 2FA for your account.
2FA(Two-factor authentication) setup needs an authenticator app in your phone: try Microsoft Authenticator, Google Authenticator or your favorite one.
2. Login to npm
npm login
It will show you something like this:
npm notice Log in on https://registry.npmjs.org/
Login at:
https://www.npmjs.com/login?next=/login/cli/<token>
Press ENTER to open in the browser...
Logged in on https://registry.npmjs.org/.
3. Upload to npm
Once you have everything ready in your package, you can upload it to npm
:
make publish
# Or
npm publish
Note: You many choose to use access tokens.
An access token is an alternative to using your username and password for authenticating to npm when using the API or the npm command-line interface (CLI). An access token is a hexadecimal string that you can use to authenticate, and which gives you the right to install and/or publish your modules.Know more here: https://docs.npmjs.com/about-access-tokens
If everything is good, you should see something like this:
npm notice
npm notice 📦 lr_grepjs@1.0.0
npm notice === Tarball Contents ===
npm notice 451B .eslintrc.cjs
npm notice 1.1kB LICENSE
npm notice 227B Makefile
npm notice 1.6kB README.md
npm notice 2.7kB bin/cmd.ts
npm notice 2.7kB dist/bin/cmd.js
npm notice 3.1kB dist/lib/grep.js
npm notice 3.4kB lib/grep.ts
npm notice 1.3kB package.json
npm notice 3.5kB test/grep.test.ts
npm notice 1.2kB tsconfig.json
npm notice === Tarball Details ===
npm notice name: lr_grepjs
npm notice version: 1.0.0
npm notice filename: lr_grepjs-1.0.0.tgz
npm notice package size: 5.8 kB
npm notice unpacked size: 21.3 kB
npm notice shasum: 801227b2d839e07b0f7069242eca1ec407b275c3
npm notice integrity: sha512-tC520UO62f7TS[...]eGa7of+XFl/BQ==
npm notice total files: 11
npm notice
npm notice Publishing to https://registry.npmjs.org/ with tag latest and default access
Authenticate your account at:
https://www.npmjs.com/auth/cli/<token>
Press ENTER to open in the browser...
+ lr_grepjs@1.0.0
6. Verify on npm
Visit npm and check if your package is listed.
7. Use it as a real package
# [Optional] Uninstall the local dev version if it's there
npm uninstall -g lr_grepjs
# Install from "real" npm
npm -g install lr_grepjs
# Try it for real
grepjs -h
Congratulations🎉! You've made a great CLI app in Node.js now.
Complete code: https://github.com/Literank/lr_grepjs
Keep Going! Keep Learning!