DEV Community

Cover image for Top Utility Packages In Javascript
sudarshan
sudarshan

Posted on

Top Utility Packages In Javascript

πŸ“’ TL:DR :

We all seek for utility packages on npm. No Matter we admire it or not, everyone (once a day or many times a day ) needs some UTILITY. So Here is the list of some utility packages which makes your life a bit easier.


πŸ›  Papa Parse :

This is the great package when we deal with files. Consider a scenario, you are building a automation system, which query's the data from third party API and process it internally and outputs processed data.

During your development, you want to process massive amount of CSV data, then *Papa Parse * is your πŸ—‘Go-to Man πŸ—‘

Here is an example

          let CSVdata = await getCSVContent(getCSVContentURL);

          let parsedData = papaParse.parse(CSVdata).data;

          console.log(
            "ParsedData is  ",
            parsedData.length
          );

Enter fullscreen mode Exit fullscreen mode

Here, after await() call, we are getting CSV file, which contains the data. Once we got the data, I used papa parse and Papa parse give me the array of objects (In my case) pretty easily without any jargon.

There is whole lot more functionality you can use


πŸ’» Puppteer:

Puppteer is the browser automation tool. It is a pretty similar as compared to Selenium or any other automation tool. But, advantage of Puppeteer, it provides wide variety of functionality with respect to headless chromium browser and lower level DOM API's

If you want to know more about it then, I have a article regarding usage of Puppteer take a look at it πŸ‘‰πŸ‘‰ Here


⚑ Cheerio ⚑:

Cheerio can be used with puppeteer. Cheerio parses the available html data and gives us the ability to interact with data and extract the useful information. It can act as parser, if you are building the πŸ” SEO scrapper πŸ” or the Resume scrapper for your organization

     const cheerio = require("cheerio")

     //jquery style
    const $ = cheerio.load(content);

    //use $ to interact with elements
Enter fullscreen mode Exit fullscreen mode

GCL :

GCL is the short form for the get-current-line. It is my favorite package. It is totally optionally to use but, if you have project where you have to implement :

  1. logging specific events to the database
  2. getting the line number, where the specific code is executed

then you must use it. It does nothing but gives you the current line of code with very simplistic API

          console.log("\n Getting current line number \n");
          let currentLineNumber = gcl.default().line;

Enter fullscreen mode Exit fullscreen mode

Pretty simple :)


πŸ€‘ Proxy Chain πŸ€‘ :

Whenever you want to apply the proxy to your nodejs, then use it undoubtedly. Proxy chain provides us the way to interact the proxy with pretty simple way. It generates the new proxy URL which you can put into the configuration and then we are good to go

Here the example usage of proxy chain

        let newProxyUrl = await proxyChain.anonymizeProxy(proxyUrl);

        launchConfigObject.args = [
          "--no-sandbox",
          "--disable-setuid-sandbox",
          `--proxy-server=${newProxyUrl}`,
        ];
        console.log("proxy executed ....");

Enter fullscreen mode Exit fullscreen mode

This is the example of proxy chain with puppeteer. While doing automation, applying proxy is non-written rule. In the above snippet, I have used anonymizeProxy() API of proxy chain which builds ready to use proxy URL for us.


πŸ– Chalk :-

If you are the fan of doing the colorful stuff in the terminal then this is for you. Chalk provides the API's which makes our terminal colorful and it is pretty light weight and flexible to use. we can directly put it into native javascript API's like console.log and use it comprehensively

image

This is the example of chalk used with the morgan.


🏏Morgan :

Morgan is used as the logger for the nodejs server it is pretty helpful to interact with the incoming requests and all these stuff happening inside the nodejs. It gives us the prebuilt modification of request logging. if you used

        app.use(morgan("dev"))
Enter fullscreen mode Exit fullscreen mode

Then it will run in developer mode and will log pretty helpful information regarding request like *execution time *, *response code * etc


β˜€ Final Thoughts β˜€ :

These is the list of 0.00000001 % of npm packages which are available to use. Using packages is pretty much optional and preference based. but, using them saves us from *Re implementing the Wheel *

Please, let me know in comments if you know any other utility packages

Thanks For Reading πŸ™

Top comments (5)

Collapse
 
sqlrob profile image
Robert Myers

This might be a bit too specific use case, but serverless. Simple deploy of functions to various cloud service.

Collapse
 
amnkhan profile image
Al Amin Khan

thanks for the post.

Collapse
 
sudarshansb143 profile image
sudarshan

Yup !

Collapse
 
hartley94 profile image
Martin Thuo

Thank you for sharing.

Collapse
 
sudarshansb143 profile image
sudarshan

:)