<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sandeep Prajapati</title>
    <description>The latest articles on DEV Community by Sandeep Prajapati (@sandeep_prajapati_8eff0f1).</description>
    <link>https://dev.to/sandeep_prajapati_8eff0f1</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1608732%2F006b2d92-c956-4756-8e65-b20db6d7d3c1.png</url>
      <title>DEV Community: Sandeep Prajapati</title>
      <link>https://dev.to/sandeep_prajapati_8eff0f1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sandeep_prajapati_8eff0f1"/>
    <language>en</language>
    <item>
      <title>How I Published My First npm Packages</title>
      <dc:creator>Sandeep Prajapati</dc:creator>
      <pubDate>Fri, 31 Jul 2026 10:10:44 +0000</pubDate>
      <link>https://dev.to/sandeep_prajapati_8eff0f1/how-i-published-my-first-npm-packages-51go</link>
      <guid>https://dev.to/sandeep_prajapati_8eff0f1/how-i-published-my-first-npm-packages-51go</guid>
      <description>&lt;h1&gt;
  
  
  How I Published My First npm Packages
&lt;/h1&gt;

&lt;p&gt;If you've ever copy-pasted the same &lt;code&gt;capitalize()&lt;/code&gt; or &lt;code&gt;isPrime()&lt;/code&gt; function into three different projects, this post is for you.&lt;/p&gt;

&lt;p&gt;I recently published my first two npm packages — &lt;strong&gt;&lt;a href="https://www.npmjs.com/package/sp-number-kit" rel="noopener noreferrer"&gt;sp-number-kit&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;a href="https://www.npmjs.com/package/sp-string-kit" rel="noopener noreferrer"&gt;sp-string-kit&lt;/a&gt;&lt;/strong&gt; — and I want to walk through the actual journey: why I built them, what tripped me up, and the exact steps to publish, test, and link your own package to GitHub.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem: Same Logic, Written Differently, Every Time
&lt;/h2&gt;

&lt;p&gt;Every developer has written an "is this number even?" check or a "convert this to camelCase" function at some point. The problem is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;same operation gets rewritten&lt;/strong&gt; across projects, teams, and even by the same developer six months apart.&lt;/li&gt;
&lt;li&gt;Different implementations of the "same" logic aren't always &lt;strong&gt;accurate&lt;/strong&gt;, which can quietly introduce bugs or &lt;strong&gt;performance issues&lt;/strong&gt; down the line.&lt;/li&gt;
&lt;li&gt;We &lt;em&gt;could&lt;/em&gt; build project-specific utility files, but they stay locked inside that one project instead of being reusable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's the gap I wanted to close. So I built two small, focused utility kits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;sp-number-kit&lt;/strong&gt; — even/odd checks, prime checks, factorial, GCD, LCM, clamp, average, and more.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;sp-string-kit&lt;/strong&gt; — capitalize, palindrome check, camelCase/snakeCase/kebabCase conversion, slugify, and more.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nothing fancy. Just small, tested, reusable functions that I (and hopefully others) can &lt;code&gt;npm install&lt;/code&gt; into any project instead of rewriting from scratch.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Trickiest Parts
&lt;/h2&gt;

&lt;p&gt;Publishing a package sounds intimidating before you've done it once. Here's what actually gave me pause:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. npm authentication with 2FA&lt;/strong&gt;&lt;br&gt;
npm now enforces &lt;strong&gt;two-factor authentication (2FA)&lt;/strong&gt; for publishing, and this is something to handle carefully. If you're not prepared for the prompt, &lt;code&gt;npm publish&lt;/code&gt; can fail or hang waiting on a one-time code you didn't expect.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Testing locally before publishing&lt;/strong&gt;&lt;br&gt;
This turned out to be the most important step in the whole process. Before every publish, I made sure to &lt;strong&gt;run every function locally against expected outputs&lt;/strong&gt; — even/odd, prime, factorial, gcd, lcm, and all the string transforms. It's easy to assume a function "obviously works" and skip this, but that's exactly how bugs slip into a published package that other people now depend on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Writing a clean, accurate README&lt;/strong&gt;&lt;br&gt;
A utility package lives or dies by its README. If someone can't tell what a function does and what it returns within 10 seconds, they'll bounce. I had to be deliberate about keeping mine clean, accurate, and complete for every exported function.&lt;/p&gt;
&lt;h2&gt;
  
  
  The "Aha" Moments
&lt;/h2&gt;

&lt;p&gt;A few things surprised me in a good way (and one in a "wish I knew earlier" way):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Publishing itself is genuinely simple.&lt;/strong&gt; Once your &lt;code&gt;package.json&lt;/code&gt; is set up correctly, it's really just &lt;code&gt;npm publish&lt;/code&gt;. All the complexity is in the prep, not the publish command itself.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Version bumps are non-negotiable.&lt;/strong&gt; Every single time you make a change, you &lt;em&gt;must&lt;/em&gt; bump the version before publishing again — npm won't let you republish the same version number, and skipping this is a rookie mistake I made early on.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;npm login&lt;/code&gt; needs a second look now.&lt;/strong&gt; Because of 2FA, logging in isn't just "type your password and go" anymore — keep this in mind so it doesn't block you mid-release.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Linking to GitHub is almost too easy.&lt;/strong&gt; You just reference your repository in &lt;code&gt;package.json&lt;/code&gt;, and npm automatically shows the GitHub link on your package page. No extra CI/CD or manual linking required.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Step-by-Step: Publish, Test, and Link to GitHub
&lt;/h2&gt;

&lt;p&gt;Here's the exact flow, from an empty folder to a live, GitHub-linked npm package — visually first, then step-by-step below.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1: Check if your package name is available
&lt;/h3&gt;

&lt;p&gt;Before writing a single line of code, check whether your desired name is already taken on npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm view sp-number-kit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If it returns package details (version, description, etc.), the name is &lt;strong&gt;already taken&lt;/strong&gt; — pick another one.&lt;/li&gt;
&lt;li&gt;If it returns a 404 / "not found" error, the name is &lt;strong&gt;free&lt;/strong&gt; and you're good to go.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Skipping this check is a common rookie mistake — you don't want to build and test everything only to find out at publish time that the name is unavailable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Set up your project
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;sp-number-kit
&lt;span class="nb"&gt;cd &lt;/span&gt;sp-number-kit
npm init &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Write your functions and export them
&lt;/h3&gt;

&lt;p&gt;Structure your code so everything is exported from a single entry point (e.g. &lt;code&gt;index.js&lt;/code&gt;), so users can do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;isPrime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;factorial&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sp-number-kit&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Test locally before touching npm
&lt;/h3&gt;

&lt;p&gt;This is the step people skip and regret. Options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;npm link&lt;/code&gt; to symlink your package into a test project locally and try every function as a real consumer would.&lt;/li&gt;
&lt;li&gt;Or add a simple test script (Jest, Vitest, or even plain Node scripts) that checks expected outputs for each function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Don't publish until every function behaves exactly as documented.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Write a clean README
&lt;/h3&gt;

&lt;p&gt;Cover: what the package does, installation command, and a usage example for &lt;strong&gt;every exported function&lt;/strong&gt;. Treat it like the first (and maybe only) thing a stranger will read before deciding to trust your package.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6: Link your package to GitHub
&lt;/h3&gt;

&lt;p&gt;In your &lt;code&gt;package.json&lt;/code&gt;, add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"repository"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"git"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://github.com/your-username/sp-number-kit.git"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"bugs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://github.com/your-username/sp-number-kit/issues"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"homepage"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://github.com/your-username/sp-number-kit#readme"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's genuinely all it takes — npm automatically shows this link on your package's npm page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 7: Log in to npm (watch out for 2FA)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you have 2FA enabled on your npm account, be ready to enter your one-time code when prompted.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 8: Publish
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm publish
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it's your first time publishing a scoped or public package, you may need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm publish &lt;span class="nt"&gt;--access&lt;/span&gt; public
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 9: Test after publishing (don't skip this!)
&lt;/h3&gt;

&lt;p&gt;Once it's live, install it fresh in a separate test folder — just like a real user would:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;test-consumer
&lt;span class="nb"&gt;cd &lt;/span&gt;test-consumer
npm init &lt;span class="nt"&gt;-y&lt;/span&gt;
npm &lt;span class="nb"&gt;install &lt;/span&gt;sp-number-kit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then write a tiny script that imports and calls each function, confirming the published version behaves exactly like your local one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 10: Bump the version for every future change
&lt;/h3&gt;

&lt;p&gt;Whenever you fix a bug or add a feature:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm version patch   &lt;span class="c"&gt;# or minor / major, depending on the change&lt;/span&gt;
npm publish
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;npm will reject a publish if the version number hasn't changed — this is your safety net against accidentally overwriting a live version.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;Publishing &lt;code&gt;sp-number-kit&lt;/code&gt; and &lt;code&gt;sp-string-kit&lt;/code&gt; taught me that the actual &lt;code&gt;npm publish&lt;/code&gt; command is the easy part — the real work is in careful local testing, a genuinely useful README, and staying on top of versioning and 2FA. If you've been putting off publishing your own utility functions, this is your sign to just try it.&lt;/p&gt;

&lt;p&gt;Check them out and let me know what you think:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;📦 &lt;a href="https://www.npmjs.com/package/sp-number-kit" rel="noopener noreferrer"&gt;sp-number-kit on npm&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📦 &lt;a href="https://www.npmjs.com/package/sp-string-kit" rel="noopener noreferrer"&gt;sp-string-kit on npm&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;💻 &lt;a href="https://github.com/sanpra-tech" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you publish your own package after reading this, drop a comment — I'd love to see it!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>npm</category>
      <category>learning</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
