Publish a Node Script to npm registry¶
-
Create an npm account if you don't have one:
-
If you're using a scoped package (starting with @), configure npm:
-
Make sure you're logged in:
-
Test your package locally:
-
Publish to npm:
Additional publishing tips¶
- Use
npm version patch/minor/major
to update version numbers - Test the package thoroughly before publishing
- Make sure your .gitignore and .npmignore are properly configured
- Include appropriate keywords in package.json for better discoverability
After publishing, users can install your package using:
npx @yourusername/terminal-portfolio
Remember to:
- Choose a unique package name
- Keep your npm account credentials secure
- Update the version number when you make changes
- Include appropriate documentation
- Test the installation process on a clean system
To further update and publish add the following script to package.json and run any of them
{
...
script: {
...
"version:patch": "npm version patch && git push && git push --tags && npm publish --access public",
"version:minor": "npm version minor && git push && git push --tags && npm publish --access public",
"version:major": "npm version major && git push && git push --tags && npm publish --access public",
"publish:patch": "git add . && git commit -m \"patch update\" && npm run version:patch",
"publish:minor": "git add . && git commit -m \"minor update\" && npm run version:minor",
"publish:major": "git add . && git commit -m \"major update\" && npm run version:major"
...
}
...
}
Now you can use these commands:
For quick version updates (if changes are already committed):
npm run version:patch # For bug fixes (1.0.0 -> 1.0.1)
npm run version:minor # For new features (1.0.0 -> 1.1.0)
npm run version:major # For breaking changes (1.0.0 -> 2.0.0)
For complete updates including committing changes:
npm run publish:patch # Commits changes and publishes patch update
npm run publish:minor # Commits changes and publishes minor update
npm run publish:major # Commits changes and publishes major update
These scripts will:
- Update the version number
- Push changes to git
- Push tags to git
- Publish to npm