JavaScript: Tips and Tricks to Programming Code with Javascript (JavaScript Computer Programming, #2) by Charlie Masterson
Publishing to Common Repositories
npm
Most programming languages are equipped with package managers or they at least have a third party package manager that enables users to pull in specific libraries for that specific programming language. For example, PHPâs manager is Composer and Ruby on Rails is RubyGems. For a standalone JavaScript engine such as Node.js you have npm. By default, your npm package will be available publicly. But you also have the option of publishing the following:
- private packages
- set up a private registry
- completely avoid publishing
However, should you decide to publish your package, then you need the package.json file. You can do this manually or use an interactive wizard for this. To begin this wizard, start by typing:
npm init
The version property should match your git tag. Include the README.md file as well. Just like GitHub, npm uses that for the page presenting your package.
Once done, publish your package by typing:
npm publish
Thatâs it! You have successfully published your npm package.
Bower
Another useful package manager called Bower surfaced a few years ago. This is a package manager designed for the web. Here, you can find all major front-end asserts. The only thing is, your library will benefit from using Bower to publish your package is if your library set up to be browser-compatible.
npm packages are primarily for JavaScript and many front-end packages still use npm but Bower is still fundamentally popular so go ahead and publish using Bower too.
To generate a bower.json file, type:
bower init
Just like npm init, the instructions are self-explanatory. Finally, to publish your package:
bower register awesomelib https://github.com/you/awesomelib
Now you have your library available for everyone to use in their Node projects or on the web!