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)