Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • See all Red Hat products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Red Hat OpenShift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • See all technologies
    • Programming languages & frameworks

      • Java
      • Python
      • JavaScript
    • System design & architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer experience

      • Productivity
      • Tools
      • GitOps
    • Automated data processing

      • AI/ML
      • Data science
      • Apache Kafka on Kubernetes
    • Platform engineering

      • DevOps
      • DevSecOps
      • Red Hat Ansible Automation Platform for applications and services
    • Secure development & architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & cloud native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • See all learning resources

    E-books

    • GitOps cookbook
    • Podman in action
    • Kubernetes operators
    • The path to GitOps
    • See all e-books

    Cheat sheets

    • Linux commands
    • Bash commands
    • Git
    • systemd commands
    • See all cheat sheets

    Documentation

    • Product documentation
    • API catalog
    • Legacy documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore the Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Checking node.js dependencies with SZero - Never lose track again.

October 26, 2016
Lucas Holmquist
Related topics:
Developer Tools

    Node.js is a JavaScript runtime built on top of Chrome's V8 JavaScript engine. It is highly event-driven, and leverages non-blocking I/O model that makes it lightweight, efficient, and incredibly productive to use. It's that last bit, "productive", that I want to focus on today.

    One of the things that i feel makes Node(and NPM) so great is the ease in which you can add and use third-party modules. As most node.js developers know, to start using an external module, you first install it:

    npm install cool-module --save

    Then we require it:

    const coolModule = require('cool-module');

    Then we use it:

    coolModule.doCoolStuff();

    Yup, pretty easy.

    However, as most node.js developers know, our dependency list in our pacakge.json can grow pretty quickly. And sometimes we lose track of where in our code we are using these dependencies. Sometimes, dare I say it, we have modules in our package.json that we don't actually use. GASP!!!

    Ok, so if you've made it this far, then you probably realize this next paragraph is going to talk about how Szero fits into what i wrote above. Productivity, package installation, and dependency management/location.

    What is SZero

    SZero is a small library that we, a small team at Red Hat, have written. It checks the dependencies you're using, and locates them in your code.

    Let's see an example.

    To get started, we need to install, preferably globally, but there is also an API that can be used

    npm install szero -g

    Lets say i have a project with two dependencies, so my package.json would have something like this

    {
      ...
      "dependencies": {
      "coolModule": "^1.1.0",
      "other": "^0.1.0"
     }
     ...
    }
    

    In your code, you've used these dependencies in various places, and we can use SZero to generate a report on the console to show where these modules are used in our code

    First we run the command and specify the directory

    $ szero /path/to/project
    
    ----------------------------------------------------------------------
    [ Declaration and file lines ]
    ----------------------------------------------------------------------
    coolModule-require('coolModule'):
    ./index.js:4
    ./index.js:6
    
    otherModule-require('otherModule'):
    ./index.js:12
    ----------------------------------------------------------------------
    [ Declaration and amount ]
    ----------------------------------------------------------------------
    coolModule-require('coolModule') --> [ 2 ]
    otherModule-require('otherModule') --> [ 1 ]
    ----------------------------------------------------------------------
    [ Unused dependencies ]
    ----------------------------------------------------------------------
    None.
    

    So what does all that mean? Well, in the first section, we see where we required the module and what the variable name we stored it in. We also see the line numbers where we use that variable. So since we stored the coolModule module in a variable called coolModule, that is why we get this format:

    coolModule-require('coolModule'):

    In the next section, SZero counts up the usage:

    coolModule-require('coolModule') --> [ 2 ]

    And the last section shows, if any, unused dependencies.

    I think this feature is very useful. I know there have been many times where i install something, then don't end up using it, but forget to uninstall it. Speaking of unused dependencies, you can specify the --ci flag if you are running in a CI environment, so if any unused dependencies are detected, it will fail your build.

    By default, the output from running szero will output directly to the console, but you can specify the --file flag to output to a file. So now lets see the command in action using an animated Gif:

    {}szero-example

    Code

    If interested, the code can be found here on github: https://github.com/bucharest-gold/szero

    Try it out, Create Issues, Submit PR's!!

    Also, for those interested in seeing what types of Node.js things are being researched for JBoss and Red Hat, checkout our issues list here: https://github.com/bucharest-gold/entente/issues

    Recent Posts

    • Right-sizing recommendations for OpenShift Virtualization

    • OpenJDK 25 now available in Red Hat Enterprise Linux 10.1

    • Migrating Red Hat Ansible Automation Platform: From RPM to container on Red Hat Enterprise Linux

    • Python 3.9 reaches end of life: What it means for RHEL users

    • Upgrade air-gapped OpenShift with self-signed certificates

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue