1.0.0 • Published 4 years ago

multieventbus v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

NPMPackageSample

Create an npm account

In order to publish an npm package, you will need an npm account, which makes sense. If you do not have one, go ahead and create an account. Login to npm Once you have created your account, login using your account credentials:

~ $ npm login

You should get a message similar to this: ~ $ npm login Username: Password: Email: (this IS public) Logged in as on https://registry.npmjs.org/. Needless to say that and will be your own username and email address.

2. Initialize The Package

Now that you are logged in, create a new directory for your package. For no obvious reason, I will call my package ‘spongepoop’. However, you can choose any other name you want for your package.

~ $ mkdir spongepoop Inside your package directory, run the initialization command: ~ $ cd spongepoop spongepoop $ npm init You will be asked a couple of questions about the name of your package, version, description and so. Enter whatever you want, you can always change things later.

Package.json file Once you are done, you will see a new package.json file created in the package root directory. All npm packages contain such a file. This file is used to describe your package and allows npm to handle the package’s dependencies. Package scope There are lots of packages on npm. The name you have chosen might have already been chosen by someone else. In this case, you can create a scoped package. A scoped package has a username (or an organization name) added onto the beginning of the package name and looks something like: @somescope/somepackagename You might have already seen this naming pattern in packages like @babel/cli, @emotion/core or @storybook/addons. For this sample package, I will stick with ‘spongepoop’. Check npm scopes for more information. Package version Each npm package needs a version number. This helps developers know if it’s safe to update to a certain version of your package without breaking their code. The versioning system npm uses is SemVer (Semantic Versioning). Basically, the version number consists of three parts: MAJOR.MINOR.PATCH For a version number 10.12.5, the major number is 10, the minor number is 12 and the patch number is 5. Version number parts should be incremented in the following manner: MAJOR version is increased when you make incompatible API changes. MINOR version is increased when you add backwards-compatible functionality. PATCH version is increased when you make backwards-compatible bug fixes. You shouldn’t have to worry about managing the version number manually. There is an npm command for bumping those numbers up: $ npm version patch # 0.1.0 -> 0.1.1 $ npm version minor # 0.2.6 -> 0.3.0 $ npm version major # 2.1.4 -> 3.0.0 Start with version number 0.1.0 then use the npm version command as you progress with the development. Note that your working directory must be clean (no uncommitted changes) to use the npm version command. Check SemVer and npm version for more information.

3. Publish Now

What you have now is sufficient to publish your package. Go ahead and try: spongepoop $ npm publish Scoped packages are private by default. If you have created a scoped package, you may need to add an access flag to make your package public: spongepoop $ npm publish --access=public A bunch of lines will appear then finally a line that looks like this:

  • spongepoop@0.1.0 This means that your package has been successfully published on npm with version number 0.1.0 and you can install it in any project just like any other npm package: another-project $ npm i spongepoop

Congrats! You’re now on npm