7 NPM Packages You Should Consider Knowing

You might love these packages

Npm stands for node package managerWhen you are working on JavaScript, you can use npm to install other people’s code packages into your project. There are hundreds of thousands of packages available on npm.

In this article, I’m going to talk about essential libraries.

1. date-fns

The first library I want to talk about is date-fns. Date-fns is also known as date functions. This library is a collection of hundreds of functions.

With these functions, you can add days to a date, compare dates, format dates, etc. You can get anything related to the Date function in this library.

By default, JavaScript dates are not easy to use. They don’t have that much functionality built into them. Date-fns is a library that adds all the functions that you need.

Here is some sample code:


2. Moment.js

Another date formatter is Moment.js. This is a free and open source JavaScript library that removes the need to use the native JavaScript Date object directly.

According to WebFX, “The library is a wrapper for the Date object (in the same way that jQuery is a wrapper for JavaScript), making the object a whole lot easier to work with.”

Some believe Moment.js is better because it allows you to import only the part of the Date function that you need.


3. Dotenv

It has zero dependencies, which means this library will be incredibly small since you’re only going to be using it in development.

It’s nice because you don’t have to download a bunch of different node modules to work with your application. Its zero-dependency module loads environment variables from a .env file into process.env.


4. Socket.IO

Socket.IO makes doing WebSocket real-time communication between servers and all of the different clients a breeze.

But what exactly does this library do?

If we go to the documentation, we can see that we need to set up a fundamental server. Socket.IO is built on top of the WebSockets API and Node.js.

It consists of:

Some implementations in other languages are also available

Here is some sample code:



UUID is called “shortid,” and it’s incredibly popular. It’s mainly used to create short non-sequential URL-friendly unique IDs.

It is very secure because cryptographically strong random values create unique IDs. UUIDs are generally used for identifying information that needs to be unique within a system or network.

You do not want a database to control the identity of records centrally.

Here is some sample code to generate a UUID:


6. Axios

Axios is everybody’s favorite fetch replacement. It is used to create web requests very similarly to fetch, but it’s so easy to use.

If you go to npm publisher, they say Axios is a “promise-based HTTP client for the browser and Node.js.” That means Axios makes it easy to send asynchronous HTTP requests to REST endpoints and perform CRUD operations.

So if you want to support old browsers, Axios is a great way to do that.

Here is some sample code:


7. Classnames

This is a simple and tiny library. It allows you to easily combine different class names based on specified conditions.

Here is some sample React code:



I hope you found this article useful. Thank you for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *