उपयोगी npm Tips and Tricks जो Developers को पता होनी चाहिए

Advertisements

हेलो दोस्तों आज मैं आपको Helpful npm Tips and Tricks बताऊंगा जो Developers को पता होनी चाहिए। तो चलिए आज के कोड स्निपेट के साथ शुरुआत करते हैं। अलग-अलग समस्याओं को प्राप्त करना पूरी तरह से एक बहुत ही अलग अनुभव देता है। आज मैं आपके साथ जो कोड स्निपेट साझा करने जा रहा हूं, वह है हेल्पफुल एनपीएम टिप्स एंड ट्रिक्स जो डेवलपर्स को पता होनी चाहिए।

उपयोगी npm Tips and Tricks जो Developers को पता होनी चाहिए

यह npm टिप्स और ट्रिक्स का एक संग्रह है जो हर डेवलपर को पता होना चाहिए। यदि आपके काम में npm संकुल के साथ काम करना शामिल है, तो आपको ये npm कमांड उपयोगी लगने चाहिए। नोड पैकेज मैनेजर, जिसे npm के रूप में भी जाना जाता है, आपके प्रोजेक्ट में जावास्क्रिप्ट पैकेजों को स्थापित और प्रबंधित करने का एक उपकरण है। और अगर आपके कंप्यूटर पर पहले से ही नोड स्थापित है, तो आपके पास पहले से ही npm है।

आपको हमारे ट्रेंडिंग कोड स्निपेट भी पसंद आ सकते हैं

Advertisements

npm Commands You Should Know

यह npm सीखने के लिए एक ट्यूटोरियल नहीं है, आधिकारिक डॉक्स आरंभ करने के लिए एक अच्छी जगह है, लेकिन युक्तियों और युक्तियों का एक संग्रह है जो आपको npm उपयोगिता के साथ और अधिक करने में मदद करेगा।

Let’s jump right into the list of useful commands:

Instantly run packages without installing

The NPM registry is a treasure trove for finding packages that do useful stuff and aren’t just for programmers.

Advertisements

उदाहरण के लिए, स्पीड-टेस्ट पैकेज आपके इंटरनेट कनेक्शन की गति दिखाता है। इमोजी पैकेज आपको टर्मिनल से इमोजी खोजने में मदद करते हैं। और वाई-फ़ाई-पासवर्ड आपके मौजूदा वाई-फ़ाई नेटवर्क का पासवर्ड जानने का एक आसान तरीका है।

You can run these utility packages directly from the command line without installing them using the npx command.

npx speed-test
npx emoj unicorn
npx public-ip-cli
npx wifi-password-cli

Install npm packages faster

You’ve probably used npm install to install packages, and dependencies, in the local node_modules folder of a project. Replace this command with npm-ci and you’ll be able to install packages significantly faster.

Advertisements
npm ci

If a node_modules folder is already present, it will be automatically removed before npm ci begins to install packages.

Recover space

If you have been working with npm packages for some time, the various node_modules folders on the disks could be consuming several gigabytes of space. The very useful npkill finds all node_modules folders on your system and lets you delete them interactively.

npx npkill

Quickly download a Git repository

अधिकांश डेवलपर Git रिपॉजिटरी को डाउनलोड करने के लिए git क्लोन कमांड का उपयोग करते हैं। हालाँकि, यह प्रक्रिया को धीमा करने वाले संपूर्ण git इतिहास को भी डाउनलोड करता है। डिजिट पैकेज स्थानीय रूप से मास्टर शाखा में नवीनतम प्रतिबद्धता डाउनलोड कर सकता है और आपको पूर्ण जीथब यूआरएल निर्दिष्ट करने की आवश्यकता नहीं है।

Advertisements
npx degit username/repo
npx degit labnol/apps-script-starter

List installed packages

उन सभी npm संकुलों की सूची तैयार करें जो वैश्विक दायरे के साथ सिस्टम पर संस्थापित हैं। केवल वर्तमान प्रोजेक्ट निर्देशिका में स्थापित पैकेजों को सूचीबद्ध करने के लिए -g ध्वज को हटा दें।

npm ls --depth=0
npm ls -g

Find unused dependencies

The depcheck command will list all the npm packages that are not used in the project based on the dependencies in package.json.

npx depcheck

Use the command npm uninstall <package-name> to uninstall any unused package.

Advertisements

Find outdated dependencies

Get a list of all outdated packages in your current project. This command checks every single module listed in the package.json file and compares it with the latest version available in the NPM registry.

Add the -g flag to get all outdated packages that are installed globally on the system.

npm outdated
npm outdated -g

Update the package versions

The ncu command will update the package.json file with the latest version of the packages listed in the dependencies and devDependencies sections.

Advertisements

Or use the npm-check -u command to update packages to their latest version in interactive mode.

npm-check
npm-check -u
ncu -u

Remove extra packages

Use the prune command to remove all packages that are installed locally but not listed in the package.json file. If the —dry-run flag is used then no changes will actually be made.

npm prune

Alternatively, you can remove the node_modules folder and run npm ci again.

Advertisements

Find vulnerable packages

निर्भरता और निर्भरता अनुभागों में सूचीबद्ध पैकेजों में कमजोरियों की जांच के लिए ऑडिट कमांड चलाएँ। सुधारों को स्वचालित रूप से लागू करने के लिए, यदि कोई हो, तो फ़िक्स फ़्लैग जोड़ें।

npm audit
npm audit fix

Useful NPM Package Websites

  • bundlephobia.com – Upload your package.json file and get an idea of how much it would cost (size-wise) to install the dependencies.
  • diff.intrinsic.com – Compare any two versions of a npm package and know which files have changed in the update.
  • npmtrends.com – Compare the relative popularity of packages across the npm registry based on the number of downloads.

Leave a Comment