How to publish your pakcage

   This writing explains How to publish your own pakcages


1. Make your account and login 

$ npm login
  • It will redirect to the browser and you can login there.


2. Make your own source code

  • Make your own source code. File name should be same as in the main property of package.json so that npm know this file is the entry point of your package.
package.json
{
  "name": "npmtest",
  ...
  "main": "index.js",
  ...
}

index.js
module.exports = () => {
    return 'hello package';
};


3. Publish your package

  • You can publish your package with following command.
$ npm publish
  • It will show some error because the name npmtest is already being used by others. 
$ npm publish

...
npm error code E403
npm error 403 403 Forbidden - PUT https://registry.npmjs.org/npmtest - You do not have permission to publish "npmtest". Are you logged in as the correct user?
npm error 403 In most cases, you or one of your dependencies are requesting
npm error 403 a package version that is forbidden by your security policy, or
npm error 403 on a server you do not have access to.
npm error A complete log of this run can be found in: /Users/user/.npm/_logs/2025-03-30T16_37_39_898Z-debug-0.log
  • If the name is already being used, but the package is not active you can ask the owner by email. You can find package owner's email by: npm owner ls [package name]
  • If you put support@napmjs.com in CC, they can help it. If a naming dispute isn't resolved between the parties within a few weeks, the npm team will help solve it.

  • To check if some name is being used or not, enter the command: npm info [package name]
  • If it is being used, it will show the information. If it is not being used, it will show npm ERR! code E404, error message, which means you can use that name.
$ npm info npmtest-9216

npm error code E404
npm error 404 Unpublished on 2025-03-28T14:55:13.197Z
npm error 404
npm error 404  'npmtest-9216' is not in this registry.
npm error 404
npm error 404 Note that you can also install from a
npm error 404 tarball, folder, http url, or git url.
npm error A complete log of this run can be found in: /Users/user/.npm/_logs/2025-03-30T16_45_15_269Z-debug-0.log


3. Update your package

  • If you re-release without upgrading the version, an error will occur, because that version was already published and you need to publish it with other version. You can update your package with followings.
$ npm version patch

$ npm version minor

$ npm version major



4. Unpublish your package

  • If you re-release without upgrading the version, an error will occur. You can update your package with this command: npm unpublish [package name] --force
$ npm unpublish npmtest-9216 --force
npm warn using --force Recommended protections disabled.
- npmtest-9216

  • Packages cannot be deleted after 72 hours of publish, so if you test to publish some packages, you would better delete it within 72 hours, otherwise other user cannot use that name.

Comments

Mostly viewed post

Web-app dev4, Google AdMob (Banner and Interstitial ads)

About this blog