paint-brush
How to automate publishing npm packages to the registryby@BuddyWorks
1,568 reads
1,568 reads

How to automate publishing npm packages to the registry

by BuddyFebruary 22nd, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

<strong>This article will show you how to configure npm modules in a proper way and use Buddy to automatically test and publish your packages</strong>
featured image - How to automate publishing npm packages to the registry
Buddy HackerNoon profile picture

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_modulecd my_first_npm_modulegit 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.