NPM REGISTRY
Create Account in www.npmjs.com
- Create an account on www.npmjs.com.
- Have username and password ready.
Publishing a Package to the npm Registry
1. Prepare your package
- Ensure package.json is in the root directory with name, version, and description.
- Make sure code is ready for distribution and build process is complete.
2. Authenticate with npm
- Log in from the command line:
ornpm loginnpm adduser - Enter username, password, and email when prompted.
3. Navigate to package directory
- Use command:
cd /path/to/your/
4. Publish the package
- For unscoped public package:
npm publish - For public organization-scoped package:
npm publish --access public - For private scoped package: no
--access publicneeded (default is private).
Important Considerations
Uniqueness
- Package name + version must be unique.
Scoped Packages
- Scoped packages have @username/package-name or @org-name/package-name format.
- Prevents naming conflicts.
- Can be public or private.
- By default, scoped packages are private; use
--access publicto make them public. - Once published, scope cannot be changed (only by name or version change).
Version Management
- Update version in package.json before publishing:
Example:npm version <new-version>npm version patch
.npmignore
- Use
.npmignoreto exclude files/folders from the package.
Scoped and Unscoped Packages
Unscoped Packages
- Traditional npm packages in global public registry.
- Names are unique across npm registry.
- Referenced by name in package.json (example:
"my-package"). - Always public.
Scoped Packages
- Belong to specific user or organization.
- Names prefixed with scope (
@username/package-name). - Multiple scopes can have same package name.
- Default is private, can be made public with
--access public.
Linking a GitHub Repository in package.json
- Add repository field in package.json to link GitHub repo.
- Example:
{
"name": "my-package",
"version": "1.0.0",
"repository": {
"type": "git",
"url": "https://github.com/your-user/your-repo.git"
}
}
References:miss send registry ppt