-
Create an npm account (if you don't have one):
- Go to https://www.npmjs.com/signup
- Create an account
-
Login to npm from your terminal:
npm login
Enter your username, password, and email when prompted.
Before publishing, make sure:
- Package name is available on npm (check at https://www.npmjs.com/package/socket-base-client-js)
- Update
package.jsonwith your repository URL (if you have one) - Update
package.jsonwith your author information - Test your package locally
- Version number is correct (follows semantic versioning)
npm view socket-base-client-jsIf it returns 404, the name is available. If it returns package info, the name is taken and you'll need to change it in package.json.
You can test your package locally before publishing:
# In the socket-base-client-js directory
npm link
# In another project where you want to test
npm link socket-base-client-jsnpm publish --dry-runThis shows what files will be included without actually publishing.
For first-time publishing:
npm publishFor updates (after first publish):
# Update version first (choose one):
npm version patch # 1.0.0 -> 1.0.1 (bug fixes)
npm version minor # 1.0.0 -> 1.1.0 (new features)
npm version major # 1.0.0 -> 2.0.0 (breaking changes)
# Then publish
npm publishOr manually update version in package.json and then:
npm publishCheck your package on npm:
https://www.npmjs.com/package/socket-base-client-js
Test installation:
npm install socket-base-client-jsIf you want to publish as a scoped package (e.g., @yourusername/socket-base-client-js):
-
Update
package.json:{ "name": "@yourusername/socket-base-client-js", ... } -
Publish with public access:
npm publish --access public
After making changes:
-
Update version:
npm version patch # or minor, or major -
Publish:
npm publish
npm unpublish socket-base-client-js
# or for a specific version
npm unpublish socket-base-client-js@1.0.0- Make sure you're logged in:
npm whoami - If the package name is taken, choose a different name
- npm has restrictions on similar package names
- Try a more unique name
- Package names must be lowercase
- Can contain hyphens and underscores
- Cannot start with a dot or underscore
- Use semantic versioning (major.minor.patch)
- Write a good README.md (already done!)
- Add tests before publishing
- Keep CHANGELOG.md to track changes
- Tag releases in git after publishing
# Login
npm login
# Check what will be published
npm publish --dry-run
# Publish
npm publish
# Update version and publish
npm version patch && npm publish
# Check if logged in
npm whoami
# View package info
npm view socket-base-client-js