What is npm dependency?

I almost see it everywhere but nobody don’t defines. What is npm dependency also why do people talk too much about them?

An NPM dependency is referring to a dependency from NPM.

Now for a slightly more useful explanation… ^-^’

NPM (Node Package Manager) is a package manager for Node.js where JavaScript developers can publish libraries.

Assuming the package is public, it can be imported to other projects by anyone. We call these “dependencies” because the project depends on the library on NPM.

For example, let’s suppose someone makes a JavaScript wrapper for the Discord API. Why should everyone make a wrapper when instead a single person can maintain it and publish it as a library?

Now everyone who wants to make a Discord bot can just import that library and done, all Discord functionality is available.

In this case, Discord.js is the library for making a Discord bot in JavaScript, which can be found at npmjs.org/package/discord.js.

1 Like

So, take installing an app on your phone from the Play/App store. Or installing an app on your computer from the Windows/Apple/Play stores. There is a place online where applications are stored, and you download and save the application you want your computer/phone/tablet.

The applications you install will enhance your system in some way – normally they add some functionality that you want.

The program that lets you do this (for example the App Store app on Macs, or the Play Store app on Android/Chrome devices) handles installing and upgrading and removing those applications via a GUI – when you’ve got it open you can navigate around and it shows pictures of the apps with some description, and you click to install them and so on.

These are basically user-friendly front ends for package managers.

Operating systems generally also allow you to not use a pretty GUI program to install things. They can have a program called a package manager which does the same thing, but is normally accessed via a command line interface. You type in the thing you want to install, or you tell the package manager to read a config file that has the applications you want installed written in it. This is much more useful if you’re, for example, a system administrator looking after lots of computers – you can specify that programs A (version 1), B (version 2) and C (version 1) are to be installed on every computer on your network. It’s also very useful if you’re a developer, because a lot of the applications you want are tools that work locally on your computer via the command line. They don’t have an pretty interface and don’t get published to the app store. Some examples of package managers include Homebrew (Macs), Chocolatey (Windows), APT (Linux); there are lots of others.

When you are developing software, you generally want to add code that gives you some specific functionality to your application. This code often already exists, people have written things you can use. This code will be a dependency: your code depends on this other code that someone else wrote.

You could just copy and paste the code, but this only really works for very small things – eg a single function, yes, but all the code that would allow you to securely take payments using PayPal in an e-commerce application, no. So there needs to be a way to automatically add (install) this code so that you don’t need to do it by hand.

It’s not useful to have a pretty GUI to add these bits of functionality: you are adding code to [and tools to work with] code. So again, you want a package manager.

For JavaScript, the most common package manager is called NPM (Node Package Manager). Node is a program that runs JavaScript outside a browser, Node Package Manager allows you to pull in code other people have written to add functionality to the program you yourself are writing.

Like the App Store app (the App Store’s “package manager”) or the Google Play app (Google Play’s “package manager”), the NPM app (a program called npm that works via the command line) has the same name as the place where most of the bits of code are stored, NPM

1 Like