Skip to content

Instantly share code, notes, and snippets.

@ch4
Forked from coolaj86/how-to-publish-to-npm.md
Created November 15, 2020 04:20
Show Gist options
  • Save ch4/5b55f5b3cbae760c51503c773671d5de to your computer and use it in GitHub Desktop.
Save ch4/5b55f5b3cbae760c51503c773671d5de to your computer and use it in GitHub Desktop.
How to publish packages to NPM

Getting Started with NPM (as a developer)

If you haven't already set your NPM author info, now you should:

npm set init.author.name "Your Name"
npm set init.author.email "[email protected]"
npm set init.author.url "http://yourblog.com"

npm adduser

Then create a package.json and publish it:

cd /path/to/your-project
npm init

# Bump the version number in package.json (and git tag) before each publish
# (npm also has `npm version major|minor|patch`)
npm version patch -m "an optional description"

npm publish ./

Tip: Check Dependencies:

# Note you may want to use one of these to make sure:
# 1. Your real dependencies are listed in package.json
# 2. Your development only dependencies are in the devDependencies section
# depcheck: https://www.npmjs.com/package/depcheck
# dependency-check: https://www.npmjs.com/package/dependency-check

Beta and Release versions

If you don't want something to install by default

npm publish ./ --tag beta

If you published a bugfix as v1.0.7 and need to set v1.1.3 back to latest

git checkout v1.0.7
npm publish ./
   
git checkout v1.1.3
npm tag [email protected] latest

Appendix

Install Node + npm

If you haven't already installed node + npm, or you'd like the latest version:

macOS, Linux:

curl -fsS https://webinstall.dev/node | bash

Windows 10:

curl.exe -fsSA "MS" https://webinstall.dev/node | powershell

Other Resources

Check out my online course

If this helped you, and if you or someone you know is just getting into development, check out my upcoming online course:

Beyond Code Bootcamp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment