
A typical situation is that there is a module in the project. The module develops, becomes an independent element and is copied into another project. Then another project. And further.
In each project, the module is updated and improved, and, at some point, it becomes not clear where the current version is. Come on, "it is not clear where the current version"! It is possible that in each project the module will have its own modifications, which will be quite difficult to put in order for use in the next project.
It is possible to restrict the creation of a separate repository for the module, for example on GitHub or Bitbucket. But adding a repository as a submodule for GIT is
the road to adventure .
But you can go further and create an npm-package based on this module. Working with such packages is very simple. You can install the npm package using the
npm install
command, and update using
npm update
.
Build Package
Creating npm packages is not at all difficult. Below, I briefly describe the moments I encountered during the publication of my first module.
')
File structure
The file structure may be completely different. It is quite reasonable to use the
grunt-init and
grunt-init-node modules for creating filesystems.
Repository on github or bitbucket
It is quite logical (but not necessary) to create a repository on GitHub or Bitbucket.
Pros:
- Bug tracker to store errors encountered by users, and possibly their solutions
- You can get useful pull request
Package.json
In order to publish a module, you need to correctly fill in package.json. How to do this is described in detail in the
documentation for npm , or more interactively
here .
Publish to npm
In order to publish a package, you need to log in to npm. If you have not registered yet:
npm adduser
After that, you will need to enter your username, password and email. After registration, npm authorizes you under the created account.
In case you have already registered with npm before - you need to log in,
npm login
Now you can publish the package by typing in the console:
npm publish
Once the package is published - it can be installed using the command
npm install
To remove a package from npm there is a command:
npm unpublish <project>[@<version>]
PS
Of course, the creation of npm-packages is not a panacea, and it is likely that this will not suit everyone, but I would call it “another way to modularity”.