npm

Image of Author
September 26, 2022 (last updated March 14, 2025)

A good resource for discovering popular libraries is npm trends.

Publishing code to npm

npm version patch will bump the patch version in package.json and create a new git commit and git tag for that version. Then, git push will push the commits to your remote. You need to also run git push --tags to push the new tags to remote as well. Next, if you're using Github you can create a release via the Github Releases UI pointing to that newest tag. Finally, run npm publish from your local repo and it will push those changes to npm.

Building libraries

Bundle your code

If you are building a npm library, consider using a tool like tsup to bundle your source code into a simple dist/ directory. Bundler tools will let you write typescript while still compiling to .js, .cjs, and create .d.ts files as well.

Use package.files

Use package.files to keep your library size small. For example, say you have a "dist" folder of your bundled javascript project. To only include that, you can defined the following.

{
  "files": ["dist"]
}

Certain files are always included, so you can be minimalistic. To see what your downloadable tarball would look like, you can run npm publish --dry-run and examine the output.