DEV Community

Cover image for How I build my first NPM package and you can, everything from starting, updating, using.
Abhay Prajapati
Abhay Prajapati

Posted on

3 1

How I build my first NPM package and you can, everything from starting, updating, using.

npm init -y
Enter fullscreen mode Exit fullscreen mode

onces the package is created, make a main.js file

touch main.js
Enter fullscreen mode Exit fullscreen mode

add main.js file in bin section, if it is not then create one.

#!/usr/bin/env node
// at the top of the main.js file.
Enter fullscreen mode Exit fullscreen mode

go write the logic of your package, what you want to do.
our simply write.

console.log('hello world this is my First Package.')
Enter fullscreen mode Exit fullscreen mode

after doing this open command palete and type

npm login
# you will be propmt for username and password and OTP
Enter fullscreen mode Exit fullscreen mode
npm publish
# this will publish your package to npm.
# make sure you are have unique name for your package.
Enter fullscreen mode Exit fullscreen mode

Updating Package:

for updating package go to your root file (main.js) and make your update.
After, this will update your package.

npm version patch/minor/major
# Patch: is nominal edits version updates last decimal.
# Minor: is minor bug fixed version, updates second last.
# Major: is major version updates Main.
Enter fullscreen mode Exit fullscreen mode

Using Package:

for using packages in your local machine type

npm i -g <package-name>
# -g is for global package, so you can access it from anywhere in you computer
Enter fullscreen mode Exit fullscreen mode
<package-name>
#  to run your package.
# console.log('hello world this is my First Package.')
Enter fullscreen mode Exit fullscreen mode

What Package I have built ? and how can you use it

This is my first package, and accutally I don't have any proper use case of this, but I am built for learning purpose

with this package you can convert you text to slug

makeslug convert this into slug
# convert-this-into-slug
Enter fullscreen mode Exit fullscreen mode

How to use it

npm i -g makeslug
Enter fullscreen mode Exit fullscreen mode
makeslug <your-text>
Enter fullscreen mode Exit fullscreen mode

So, this is simple story of my first package.

View on NPM

🤝🏾Connect me on:
Twitter: 🕊️@Abhayprajapati_
Github: 🐧@theabhayprajapati
Linkedin: 📌@abhayprajaapati
Youtube: 📺@Abhayprajapati

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more