Skip to main content

Publishing your javascript module to npm

Submitted by daniel on

Assuming you have a repository already set up, publishing and making your code available via the npm registry and package manager is pretty straightforward. 

Login in to NPM

In order to publish to the npm registry, you need to have an npm user and you need to be logged in as that user on the command line.

First, check whether you are logged in by running:

npm whoami

If you are logged in, it will show your username. Otherwise, it will show Not authed. Run 'npm adduser'

The npm adduser command can be used to create a user, or to log in as an existing user. It will prompt you for your username, password, and email address.

$ npm adduser
Username:
Password:
Email: (this IS public)

The credentials will be stored in a file called .npmrc, so you should only need to login once.

Creating a package.json 

The easiest way to get create your package.json is to cd into the root of your project’s directory and use npm init to autogenerate it. It will prompt you with a series of questions.

Make sure to add the keywords jquery-plugin and ecosystem:jquery when it prompts you for keywords.

Publishing your package

Now that you have your package.json file in place, you can publish to the npm registry. npm uses semantic versioning. 

Based on the semantic versioning rules, you may need to create a new version of your package, either change the version number in your package.json file, or run npm version <type>. For example, to make a patch release, you would use npm version patch. This will increment your version in your package.json file and will also create a tag in your git repo.

After that, run npm publish to publish your package to the npm registry. If it worked, you should see a page for your package at npmjs.com/package/package_name.

Updating your package

Just remember to increment your package version and then simply run npm publish again.

Further info

https://blog.npmjs.org

Add new comment

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.