Image Credit: Bing Image Creator plus some Photoshop
Image Credit: Bing Image Creator plus some Photoshop

Data Playground Part 2: Publishing a New NPM Package

Sencer ÖZTÜFEKÇİ
4 min readJan 20, 2024

In the first part of the trilogy, we established a new package for our experimental playground. What we’re going to do with this package is generate data in bulk and conduct performance measurements with that data. As you may already know, we have written several functions capable of generating random personal data, signal data of the most common signal types, and timestamp series. In this article, we will package all those functions and create and publish a brand new NPM package. But if you haven’t read the first part yet, please take a look at the link below, where I explain how we created this package.

Data Playground Part 1: Crafting Realism the Fun Way

Few Arrangements

Before we publish our new package to NPM, we need to make a few adjustments:

const person = require("./generators/person/index.js");
const signals = require("./generators/signals/index.js");
const time = require("./generators/time/index.js");

module.exports = {
person,
signals,
time,
};

The first adjustment is to export our functions in a single module. This way, other developers will be able to use our package in their own code.

The second thing we need to do is add new fields to the package.json:

{
"name": "random-data-gen",
"version": "1.0.5",
"author": "Sencer Öztüfekçi <tufekcisencer@gmail.com>",
"repository": {
"type": "git",
"url": "git+https://github.com/gomestai/randomDataGenerator.git"
},
"keywords": [
"random",
"data",
"generator",
"random data generator",
"mock data",
"mock data generator"
],
"license": "MIT"
}

The fields we need to update are the repository, keywords, and license. This is necessary to show which words can be used when searching for our package. Additionally, the license type and the Git repository address are among the pieces of information we want to display for other developers.

The last thing we need to do is write a readme.md file. Creating a readme is beneficial for informing other developers on how to use our package. A readme file is displayed on the npm package page and the repository’s main page.

This is how readme.md file look like in NPM

Here’s a list of quick indicators in case you need to create your own readme.md file. Markdown files use styling indicators. The indicators I used when writing this package’s readme.md file are:

# The hashtag is used for highest order title, or maybe h1 in html, you can go down to h2 by nesting more # side by side.

Another indicator is ``` this one is used for creating codesnippets in readme file. You can type the language after ``` to determine colorization of codes in snippet like this ```javascript.

Publishing The Package

So far so good. We created a readme.md file, describe the licence, keywords and repository address in package.json. Now first you need to create a new account in NPM and login your newly created account by using npm cli tools. If you have an account, please type npm login in your terminal to start authentication process

Then hit enter to open logging in confrimation page on your default browser. If you have two-factor authentication which is highly recommended.

Type your OTP and you’ll se this

And in your terminal, it’s clear that you are ready to publish your very first package to the NPM.

Now go to your projects parent folder which contains package.json file and type npm publish.

If everything goes well you will see the above output, and your package is instantly available to other developers. Congratulations! You’ve released your first NPM package!

The name of our new package is random-data-gen. You can access the package here.

I was happy to see that more than 300 people used the package I published in the 10 days following its publication. It’s a rewarding experience to give something new to the community in return for what you’ve been taking from it for so long.

Thus, we have completed the second part of our article trilogy. In the next article, we will focus on how we can achieve higher performance by reading the data we produce. We will create plenty of data with this newly published library. We will discuss where auto-incrementing PKs and UUIDs should be used. Stay tuned for the third and the most exciting part.

After publishing the first article, I made some changes to the code. You can access all these changes and the repo address of the code from this link.

Until next time, happy coding!

--

--