<?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: Abdelkader Bouzomita</title>
    <description>The latest articles on DEV Community by Abdelkader Bouzomita (@abdelkader_bouzomita_c34e).</description>
    <link>https://dev.to/abdelkader_bouzomita_c34e</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1647901%2Ff60f0cc6-eb33-4acb-a298-d39994244d5e.jpeg</url>
      <title>DEV Community: Abdelkader Bouzomita</title>
      <link>https://dev.to/abdelkader_bouzomita_c34e</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abdelkader_bouzomita_c34e"/>
    <language>en</language>
    <item>
      <title>How to Create and Publish Your Own NPM Package</title>
      <dc:creator>Abdelkader Bouzomita</dc:creator>
      <pubDate>Mon, 21 Apr 2025 19:08:08 +0000</pubDate>
      <link>https://dev.to/abdelkader_bouzomita_c34e/how-to-create-and-publish-your-own-npm-package-4okk</link>
      <guid>https://dev.to/abdelkader_bouzomita_c34e/how-to-create-and-publish-your-own-npm-package-4okk</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2xjfse6k0fhzihklfkrv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2xjfse6k0fhzihklfkrv.png" alt="npm package image " width="466" height="478"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Introduction
&lt;/h3&gt;

&lt;p&gt;In this guide, I’ll walk you through the entire process of creating and publishing your first NPM package — from setting up your project, writing the code, and testing it locally, to pushing it live on the NPM registry. Whether you’re building a small utility or planning a larger open-source project, this article will give you a solid starting point.&lt;/p&gt;

&lt;p&gt;Creating your own NPM package allows you to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reuse your code across multiple projects.&lt;/li&gt;
&lt;li&gt;Share useful tools with the dev community.&lt;/li&gt;
&lt;li&gt;Build a portfolio and get recognised for your work.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  2. Prerequisites
&lt;/h3&gt;

&lt;p&gt;Basic knowledge of JavaScript/TypeScript.&lt;br&gt;
Node.js and npm installed.&lt;br&gt;
An npm account.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Setting Up Your Project
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir my-awesome-package
cd my-awesome-package
npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  4. Writing Your Package Code
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Create an index.js or index.ts file.&lt;br&gt;
my-awesome-package/&lt;br&gt;
├── src/&lt;br&gt;
│ └── index.js (or index.ts)&lt;br&gt;
├── package.json&lt;br&gt;
└── README.md&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * Capitalizes the first letter of a string
 * @param {string} str - The string to capitalize
 * @returns {string} The capitalized string
 */

function capitalize(str) {
  if (typeof str !== 'string') {
    throw new TypeError('Expected a string');
  }

  return str.charAt(0).toUpperCase() + str.slice(1);
}

module.exports = capitalize;
{
  "name": "my-awesome-package",
  "version": "1.0.0",
  "main": "src/index.js",
  ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. Testing Locally
&lt;/h3&gt;

&lt;p&gt;How to test your package locally in another project using npm link.&lt;br&gt;
Before publishing your package to the world, you’ll want to test it in a real-world environment — like another project that uses your package.&lt;br&gt;
That’s where &lt;code&gt;npm link&lt;/code&gt; comes in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ~/projects/my-awesome-package
npm link
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes your local package globally available (as if it was published).&lt;/p&gt;

&lt;p&gt;You’ll see a message like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/Users/you/.nvm/versions/node/v18.0.0/lib/node_modules/my-awesome-package -&amp;gt; /Users/you/projects/my-awesome-package&lt;/code&gt;&lt;br&gt;
go to the test project:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd ~/projects/test-app&lt;br&gt;
npm link my-awesome-package&lt;/code&gt;&lt;br&gt;
In your test project, you can now import your package like this:&lt;/p&gt;

&lt;p&gt;// test-app/index.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const capitalize = require('my-awesome-package');

console.log(capitalize("linked!")); // Output: "Linked!"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6. Adding README.md
&lt;/h3&gt;

&lt;p&gt;Your code may be brilliant — but if no one knows what it does or how to use it, it won’t go far.&lt;br&gt;
That’s why a clear, concise, and helpful README.md is essential.&lt;br&gt;
Here’s a simple but effective layout for your README.md:&lt;/p&gt;
&lt;h4&gt;
  
  
  My Awesome Package
&lt;/h4&gt;

&lt;p&gt;`Short description&lt;/p&gt;
&lt;h4&gt;
  
  
  🚀 Installation
&lt;/h4&gt;

&lt;p&gt;How to install the package&lt;/p&gt;
&lt;h4&gt;
  
  
  🧠 Usage
&lt;/h4&gt;

&lt;p&gt;Examples of how to use it&lt;/p&gt;
&lt;h4&gt;
  
  
  🛠 API
&lt;/h4&gt;

&lt;p&gt;Function definitions (inputs/outputs)&lt;/p&gt;
&lt;h4&gt;
  
  
  📦 License`
&lt;/h4&gt;

&lt;p&gt;Open source license info (MIT, ISC, etc.)&lt;br&gt;
Tools You Can Use:&lt;br&gt;
Markdown preview plugins in VS Code to check how it looks&lt;/p&gt;
&lt;h3&gt;
  
  
  7. Ignoring Unwanted Files
&lt;/h3&gt;

&lt;p&gt;When you publish an NPM package, you want to keep it clean, small, and relevant. That means:&lt;/p&gt;

&lt;p&gt;✅ Include only what's necessary for users.&lt;br&gt;
❌ Exclude dev files, tests, local configs, build tools, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;.gitignore&lt;/strong&gt;:Prevents files from being tracked in Git&lt;br&gt;
&lt;strong&gt;.npmignore&lt;/strong&gt;:Prevents files from being included in your NPM package&lt;br&gt;
Example: .gitignore&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Node modules
node_modules/

# Build output
dist/
build/

# Logs
*.log

# IDE/editor files
.vscode/
.idea/

# Environment
.env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example: .npmignore&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Don't publish source files or configs
src/
tests/
__tests__/
coverage/
.eslintrc.json
.prettierrc
tsconfig.json
.vitest.config.ts
.vscode/
.env

# Ignore lockfiles
package-lock.json
yarn.lock

# Ignore other dev tools
*.log
Generally, you only want to include:
dist/
README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;LICENSE&lt;br&gt;
package.json&lt;br&gt;
index.js (or main entry)&lt;br&gt;
types/ (if TypeScript types are generated)&lt;/p&gt;
&lt;h2&gt;
  
  
  8. Publishing to NPM
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Create an NPM Account (if you haven't)&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;npm login&lt;/code&gt;&lt;br&gt;
It will ask for:&lt;br&gt;
your username&lt;br&gt;
your password&lt;br&gt;
your email&lt;/p&gt;

&lt;p&gt;Once logged in successfully, your credentials are saved and you're ready to publish!&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2: Check your package.json
&lt;/h3&gt;

&lt;p&gt;Make sure the essential fields are filled correctly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "your-package-name", // must be unique!
  "version": "1.0.0",
  "description": "A simple utility that does X",
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "scripts": {
    "build": "tsc",
    "test": "vitest"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/your-username/your-repo.git"
  },
  "keywords": ["utility", "npm", "typescript"],
  "author": "Your Name",
  "license": "MIT"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Don't forget to make sure the package name is unique!&lt;br&gt;
Step 3: Build Before Publishing&lt;br&gt;
If you're using TypeScript or need a build step, make sure everything is compiled first:&lt;br&gt;
npm run build&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 4: Preview What Will Be Published
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;npm pack --dry-run&lt;/code&gt;&lt;br&gt;
It will show which files will be included in your package. Example output:&lt;br&gt;
&lt;code&gt;npm notice 📦  my-awesome-package@1.0.0&lt;br&gt;
npm notice === Tarball Contents ===&lt;br&gt;
npm notice 1.1kB  package.json&lt;br&gt;
npm notice 3.4kB  dist/index.js&lt;br&gt;
npm notice 1.2kB  README.md&lt;br&gt;
npm notice === Tarball Details ===&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 5: Publish It!
&lt;/h3&gt;


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

&lt;/div&gt;


&lt;p&gt;And that's it - your package is live!&lt;/p&gt;
&lt;h3&gt;
  
  
  9. Versioning Your Package
&lt;/h3&gt;

&lt;p&gt;When you're maintaining an NPM package, versioning is critical. It helps developers (including your future self) understand how updates might affect existing projects that use your package.&lt;/p&gt;

&lt;p&gt;What is Semantic Versioning?&lt;br&gt;
NPM follows Semantic Versioning - usually written like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MAJOR.MINOR.PATCH
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each part has a specific meaning:&lt;br&gt;
&lt;strong&gt;MAJOR&lt;/strong&gt;: Breaking changes - the API has changed in a way that may not be backward compatible.&lt;br&gt;
&lt;strong&gt;MINOR&lt;/strong&gt;: New features added in a backward-compatible manner.&lt;br&gt;
&lt;strong&gt;PATCH&lt;/strong&gt;: Bug fixes or small updates that don't break anything.&lt;br&gt;
&lt;code&gt;npm version patch   # bumps 1.0.0 → 1.0.1&lt;br&gt;
npm version minor   # bumps 1.0.1 → 1.1.0&lt;br&gt;
npm version major   # bumps 1.1.0 → 2.0.0&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you found this helpful, feel free to share it with others, drop a comment, or follow me for more dev content!&lt;br&gt;
Happy coding 👨‍💻👩‍💻&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>npm</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
