npm

I want to learn more about npm (node package manager).

Date Created:
2 471

References



Notes


npm is the world's largest software registry. Open source developers from every content use npm to share and borrow packages, and many organizations use npm to manage private development as well. npm consists of three distinct components:
  • the website
    • Use the website to discover packages, set up profiles, and manage other aspects of your npm experience.
  • the Command Line Interface (CLI)
    • The CLI runs from a terminal and is how most developers interact with npm
  • the registry
    • the registry is a large public database of JavaScript software and the meta-information surrounding it

Use npm to:

  • adapt packages of code for your apps, or incorporate packages as they are
  • Download standalone tools you can use right away
  • Run packages without downloading using npx
  • ...

The public npm registry is a database of JavaScript packages, each comprised of software and metadata. Open source developers and developers at companies use the npm registry to contribute packages to the entire community or members of their organizations, and download packages to use in their own projects.

A package is a file or directory that is described by package.json file. A package must contain a package.json file in order to be published to the npm registry.

A module is any file or directory in the node_modules directory that can be loaded by the Node.js require() function. To be loaded by the Node.jsrequire() function, a module must be one of the following:

  • A folder with a package.json file containing a "main" field.
  • A JavaScript file.

In the context of a Node program, the module is also the thing that was loaded from a file.

You can install a package locally if you want to depend on the package from your own module, using something like Node.js require. This is npm install's default behavior. To install a public package, on the command line, run:

$ npm install <package_name>

Installing a package globally allows you to use the code in the package as a set of tools on your local computer. To download and install packages globally, on the command line, run the following command:

$ npm install -g <package_name>

An Introduction to the NPM Package Manager

npm is the standard package manager for Node.js. In September 2022, over 2.1 million packages were reported being listed in the npm registry, making it the biggest single language code repository on Earth, and you can be sure there is a package for almost everything. npm installs, updates, and manages downloads of dependencies of your projects. Dependencies are pre-build pieces of code, such as libraries and packages, that your Node.js application needs to work. npm installs, updates, and manages downloads of dependencies of your project. Dependencies are pre-built pieces of code, such as libraries and packages, that your Node.js application needs to work.

If your package has a package.json file, by running

$ npm install

it will install everything the project needs, in the node_modules folder, creating it if it's not existing already.

You can also install a specific package by running:

$ npm install <package-name>

More flags can be added to the above command:

  • --save-dev: installs and saves the entry to package.json file devDependencies
  • --no-save: installs but does not add the entry to the package.json file dependencies
  • --save-optional: installs and adds the entry to the package.json optionalDependencies
  • --no-optional: will prevent optional dependencies from being installed

The difference between devDependencies and dependencies is that the former contains development tools, like a testing library, while the latter is bundled with the app in production. As for the optionalDependencies, the differenece is that build failure of the dependency will not cause installation to fail. But it is your program's responsibility to handle the lack of the dependency. updating is made easy by running:

$ npm update [<package_name>]

Comments

You have to be logged in to add a comment

User Comments

Insert Math Markup

ESC
About Inserting Math Content
Display Style:

Embed News Content

ESC
About Embedding News Content

Embed Youtube Video

ESC
Embedding Youtube Videos

Embed TikTok Video

ESC
Embedding TikTok Videos

Embed X Post

ESC
Embedding X Posts

Embed Instagram Post

ESC
Embedding Instagram Posts

Insert Details Element

ESC

Example Output:

Summary Title
You will be able to insert content here after confirming the title of the <details> element.

Insert Table

ESC
Customization
Align:
Preview:

Insert Horizontal Rule

#000000

Preview:


View Content At Different Sizes

ESC

Edit Style of Block Nodes

ESC

Edit the background color, default text color, margin, padding, and border of block nodes. Editable block nodes include paragraphs, headers, and lists.

#ffffff
#000000

Edit Selected Cells

Change the background color, vertical align, and borders of the cells in the current selection.

#ffffff
Vertical Align:
Border
#000000
Border Style:

Edit Table

ESC
Customization:
Align:

Upload Lexical State

ESC

Upload a .lexical file. If the file type matches the type of the current editor, then a preview will be shown below the file input.

Upload 3D Object

ESC

Upload Jupyter Notebook

ESC

Upload a Jupyter notebook and embed the resulting HTML in the text editor.

Insert Custom HTML

ESC

Edit Image Background Color

ESC
#ffffff

Insert Columns Layout

ESC
Column Type:

Select Code Language

ESC
Select Coding Language

Insert Chart

ESC

Use the search box below

Upload Previous Version of Article State

ESC