Buddy

@BuddyWorks

How to automate publishing npm packages to the registry

This article will show you how to configure npm modules in a proper way and use Buddy to automatically test and publish your packages

Objectives of this guide

This guide will show you how to:

  • Create an npm package
  • Publish the package in the registry
  • Automate testing and publishing of the npm package thanks to Buddy

Requirements

The first thing you need to do is to install the following things:

Creating an npm package

Begin with creating a folder and initializing a Git repository so that your package remains safe under version control:

mkdir my_first_npm_module
cd my_first_npm_module
git init

Next, add package.json which will contain the details of your module. You can easily do that by running this command:

npm init

You will be asked to provide the information about your package:

  • name
  • version
  • main value (usually set to index.js)

Once done, check the contents of package.json. It should look like this:

{
"name": "buddy-demo-package",
"version": "1.0.3",
"description": "",
 "main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

In index.js the functions should be provided as a property of the exports object. Here's an example:

exports.printMsg = function() {    
console.log("My first package message");
}

Once everything is set, make sure to commit your files to the repo…

Like what you read? Follow the full article here.

Hacker Noon is how hackers start their afternoons. We’re a part of the @AMI family. We are now accepting submissions and happy to discuss advertising & sponsorship opportunities.
If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories. Until next time, don’t take the realities of the world for granted!

More by Buddy

Topics of interest

More Related Stories