DEV Community

aistore2030 dot com
aistore2030 dot com

Posted on

πŸ“’ Introducing `saksh-pc2`: A Simple Node.js Package Checker

πŸ” The Problem: "Module Not Found" Errors

If you’ve ever worked on a Node.js project, you’ve likely faced this frustrating error:

Error: Cannot find module 'express'
Enter fullscreen mode Exit fullscreen mode

It usually happens when a required package is missing from node_modules. The solution? Running:

npm install express
Enter fullscreen mode Exit fullscreen mode

But what if you could automate this process and instantly check for missing dependencies before running your script? That’s where saksh-pc2 comes in. 🎯


πŸš€ Meet saksh-pc2 - A Lightweight Package Checker

saksh-pc2 is a simple command-line tool that scans a JavaScript file for external dependencies and suggests an npm install command to install them.

It works with both:
βœ… CommonJS (require())

βœ… ES Modules (import)

How It Works

When you run:

saksh-pc2 app.js
Enter fullscreen mode Exit fullscreen mode

It scans app.js and lists all external dependencies used in the file.

Example Output

If app.js contains:

const express = require("express");
const mongoose = require("mongoose");

console.log("Server running...");
Enter fullscreen mode Exit fullscreen mode

Running:

saksh-pc2 app.js
Enter fullscreen mode Exit fullscreen mode

Will output:

πŸ“¦ Detected external packages:

express
mongoose

πŸ’‘ To install them, run:

npm install express mongoose
Enter fullscreen mode Exit fullscreen mode

If no external packages are found, it simply says:

βœ… No external packages detected.
Enter fullscreen mode Exit fullscreen mode

πŸ› οΈ How to Install saksh-pc2

Getting started is super easy! Just install it globally using NPM:

npm install -g saksh-pc2
Enter fullscreen mode Exit fullscreen mode

Then, you can use the command anywhere:

saksh-pc2 myscript.js
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ Why Use saksh-pc2?

βœ” Saves time – Avoids manual dependency checks.

βœ” Prevents errors – No more "Module Not Found" surprises.

βœ” Simple & lightweight – No extra dependencies.

βœ” Fast scanning – Works in seconds.


πŸ”§ Advanced Usage: Auto-Install Missing Packages

Want to automatically install missing dependencies? Use this command:

saksh-pc2 app.js | xargs npm install
Enter fullscreen mode Exit fullscreen mode

This will:
1️⃣ Scan for missing packages.

2️⃣ Pipe the package names to npm install.

3️⃣ Install everything in one go! πŸŽ‰


πŸ”— Get Started Today!

If you want a quick and efficient way to check missing dependencies in Node.js, saksh-pc2 is the perfect tool. Install it today and never worry about missing packages again! πŸš€

npm install -g saksh-pc2
Enter fullscreen mode Exit fullscreen mode

Then, scan your scripts:

saksh-pc2 myscript.js
Enter fullscreen mode Exit fullscreen mode

Check it out and let us know what you think!

We’d love your feedback, contributions, and suggestions. πŸ’¬

Top comments (0)