Creating an NPM module
How to
- Create a repo that can be published as a public (unscoped) NPM module
- Register an account on npmjs.com
- Publish the module to NPM
- Add the dependency to a project
- Make the repo available in the cloud (optional)
1. Create a project that can be published as an NPM module
- Follow the instructions under "Create a package.json file" from the NPM docs
- Follow the instructions under "Create the file that will be loaded ..." from the NPM docs
2. Register an account on npmjs.com
- Go to npmjs.org > join and register an account
- login in the terminal:
$ npm login
3. Publish the module to NPM
$ npm publish
4. Add the dependency to a node project
Go to a separate project and add it with yarn or npm. Below we assume that the project was named npm-test-em:
$ yarn add npm-test-em
5. Make the repo available in the cloud
- Create a repo on github/gitlab or similar and follow the instructions to push your local project to the cloud
- Add the repo information to package.json:
// package.json
{
// ...
"repository": {
"type": "git",
"url": "https://gitlab.com/emlabs/npm-test-module.git"
}
// ...
}
Examples
References
- Creating npm modules NPM documentation