Npm

Last updated

npm
Original author(s) Isaac Z. Schlueter
Developer(s) npm, Inc. (a subsidiary of GitHub, [1] a subsidiary of Microsoft)
Initial release12 January 2010;14 years ago (2010-01-12) [2]
Stable release
10.5.2 [3]   OOjs UI icon edit-ltr-progressive.svg / 10 April 2024
Repository
Written in JavaScript
Platform Cross-platform
Type Package manager
License Artistic License 2.0
Website www.npmjs.com

npm is a package manager for the JavaScript programming language maintained by Microsoft's npm, Inc. npm is the default package manager for the JavaScript runtime environment Node.js and is included as a recommended feature in the Node.js installer. [4]

Contents

It consists of a command line client, also called npm, and an online database of public and paid-for private packages, called the npm registry. The registry is accessed via the client, and the available packages can be browsed and searched via the npm website. The package manager and the registry are managed by npm, Inc.

While "npm" is commonly understood to be an abbreviation for "Node Package Manager", it's officially a recursive backronym for "npm is not an acronym". [5]

History

npm was developed by Isaac Z. Schlueter as a result of having "seen module packaging done terribly" and with inspiration from other similar projects such as PEAR (PHP) and CPAN (Perl). [6] npm is a JavaScript replacement for pm, a shell script. [7]

In March 2020 it was announced that npm is to be acquired by GitHub. [1]

Usage

npm can manage packages that are local dependencies of a particular project, as well as globally-installed JavaScript tools. [8] When used as a dependency manager for a local project, npm can install, in one command, all the dependencies of a project through the package.json file. [9] In the package.json file, each dependency can specify a range of valid versions using the semantic versioning scheme, allowing developers to auto-update their packages while at the same time avoiding unwanted breaking changes. [10] npm also provides version-bumping tools for developers to tag their packages with a particular version. [11] npm also provides the package-lock.json [12] file which has the entry of the exact version used by the project after evaluating semantic versioning in package.json.

Client

npm's command-line interface client allows users to consume and distribute JavaScript modules that are available in the registry. [13]

In February 2018, an issue was discovered in version 5.7.0 in which running sudo npm on Linux systems would change the ownership of system files, permanently breaking the operating system. [14]

In npm version 6, the audit feature was introduced to help developers identify and fix security vulnerabilities in installed packages. [15] The source of security vulnerabilities were taken from reports found on the Node Security Platform (NSP) and has been integrated with npm since npm's acquisition of NSP. [16]

Registry

Packages in the registry are in ECMAScript Module (ESM) or CommonJS format and include a metadata file in JSON format. [17]

Over 1.3 million packages are available in the main npm registry. [18]

The registry does not have any vetting process for submission, which means that packages found there can potentially be low quality, insecure, or malicious. [17] Instead, npm relies on user reports to take down packages if they violate policies by being low quality, insecure, or malicious. [19] npm exposes statistics including number of downloads and number of depending packages to assist developers in judging the quality of packages. [20]

Internally npm relies on the NoSQL Couch DB to manage publicly available data. [21]

Security and disruption

left-pad

In March 2016, a package called left-pad was unpublished as the result of a naming dispute between Azer Koçulu, an individual software engineer, and Kik. [22] [23] The package was immensely popular on the platform, being depended on by thousands of projects and reaching 15 million downloads prior to its removal. [22] [24] Several projects critical to the JavaScript ecosystem including Babel and Webpack depended on left-pad and were rendered unusable. [25] Although the package was republished three hours later, [26] it caused widespread disruption, leading npm to change its policies regarding unpublishing to prevent a similar event in the future. [27]

peacenotwar

In March 2022, developer Brandon Nozaki Miller, maintainer of the node-ipc package, added peacenotwar as a dependency to the package; peacenotwar recursively overwrites an affected machine's hard drive contents with the heart emoji if they have a Belarusian or Russian IP address. The package also leaves a text file on the machine containing a message in protest of the Russian invasion of Ukraine. Vue.js, which uses node-ipc as a dependency, did not pin its dependencies to a safe version, meaning that some users of Vue.js became affected by the malicious package if the dependency was fetched as the latest package. [28] [29] The affected dependency was also briefly present in version 3.1 of Unity Hub; a hotfix was released the same day to remove the issue, however. [30]

Other notable incidents

In November 2018, it was discovered that a malicious package had been added as a dependency to version 3.3.6 of the popular package event-stream. [31] The malicious package, called flatmap-stream, contained an encrypted payload that stole bitcoins from certain applications. [32]

In May 2021, pac-resolver, an npm package that received over 3 million downloads per week, was discovered to have a remote code execution vulnerability. [33] The vulnerability resulted from how the package handed config files, and was fixed in versions 5 and greater. [34]

In January 2022, the maintainer of the popular package colors pushed changes printing garbage text in an infinite loop. [24] The maintainer also cleared the repository of another popular package, faker, and its package on npm, and replaced it with a README that read, "What really happened to Aaron Swartz?" [35]

In May 2023, several npm packages including bignum were found to be exploited, stealing user credentials and information from affected machines. Researchers discovered that these packages had been compromised through an exploit involving Amazon S3 buckets and the node-gyp command line tool. [36]

Alternatives

There are a number of open-source alternatives to npm for installing modular JavaScript, including Yarn, [37] Bun and Deno. Deno and Bun also provide a JavaScript runtime, while only Deno operates independently from NPM Registry or any centralized repository [38] and its support of NPM registry is still a subject of ongoing work in progress as of January 2024. [39] They are all compatible with the public npm registry and use it by default, but provide different client-side experiences, usually focused on improving performance and determinism compared to the npm client. [40]

See also

Related Research Articles

The Comprehensive Perl Archive Network (CPAN) is a repository of over 250,000 software modules and accompanying documentation for 39,000 distributions, written in the Perl programming language by over 12,000 contributors. CPAN can denote either the archive network or the Perl program that acts as an interface to the network and as an automated software installer. Most software on CPAN is free and open source software.

<span class="mw-page-title-main">Google Closure Tools</span> JavaScript developer toolkit

Google Closure Tools is a set of tools to help developers build rich web applications with JavaScript. It was developed by Google for use in their web applications such as Gmail, Google Docs and Google Maps. As of 2023, the project had over 230K LOCs not counting the embedded Mozilla Rhino compiler.

<span class="mw-page-title-main">Node.js</span> JavaScript runtime environment

Node.js is a cross-platform, open-source JavaScript runtime environment that can run on Windows, Linux, Unix, macOS, and more. Node.js runs on the V8 JavaScript engine, and executes JavaScript code outside a web browser.

<span class="mw-page-title-main">Amber Smalltalk</span>

Amber Smalltalk, formerly named Jtalk, is an implementation of the programming language Smalltalk-80, that runs on the JavaScript runtime of a web browser. It is designed to enable client-side development using Smalltalk. The programming environment in Amber is named Helios.

Mustache is a web template system. Mustache is described as a logic-less system because it lacks any explicit control flow statements, like if and else conditionals or for loops; however, both looping and conditional evaluation can be achieved using section tags processing lists and anonymous functions (lambdas). It is named "Mustache" because of heavy use of braces, { }, that resemble a sideways moustache. Mustache is used mainly for mobile and web applications.

<span class="mw-page-title-main">Socket.IO</span> Library for realtime web applications

Socket.IO is an event-driven library for real-time web applications. It enables real-time, bi-directional communication between web clients and servers. It consists of two components: a client, and a server. Both components have a nearly identical API.

<span class="mw-page-title-main">Ember.js</span> JavaScript framework

Ember.js is an open-source JavaScript web framework that utilizes a component-service pattern. It is designed with the aim of allowing developers to create scalable single-page web applications by incorporating common idioms, best practices, and patterns from other single-page-app ecosystem patterns into the framework.

<span class="mw-page-title-main">Composer (software)</span> Software; application level dependency manager for the PHP programming language

Composer is an application-level dependency manager for the PHP programming language that provides a standard format for managing dependencies of PHP software and required libraries. It was developed by Nils Adermann and Jordi Boggiano, who continue to manage the project. They began development in April 2011 and first released it on March 1, 2012. Composer is strongly inspired by Node.js's "npm" and Ruby's "bundler". The project's dependency solving algorithm started out as a PHP-based port of openSUSE's libzypp SAT solver.

<span class="mw-page-title-main">Browserify</span> Open-source JavaScript tool

Browserify is an open-source JavaScript bundler tool that allows developers to write and use Node.js-style modules that compile for use in the browser.

<span class="mw-page-title-main">Webpack</span> Open-source JavaScript module bundler

Webpack is a free and open-source module bundler for JavaScript. It is made primarily for JavaScript, but it can transform front-end assets such as HTML, CSS, and images if the corresponding loaders are included. Webpack takes modules with dependencies and generates static assets representing those modules.

NativeScript is an open-source framework to develop mobile apps on the iOS and Android platforms. It was originally conceived and developed by Progress. At the end of 2019 responsibility for the NativeScript project was taken over by long-time Progress partner, nStudio. In December 2020 nStudio also oversaw the induction of NativeScript into OpenJS Foundation as an Incubating Project. NativeScript apps are built using JavaScript, or by using any programming language that transpiles to JavaScript, such as TypeScript. NativeScript supports the Angular and Vue JavaScript frameworks. Mobile applications built with NativeScript result in fully native apps, which use the same APIs as if they were developed in Xcode or Android Studio. Additionally, software developers can re-purpose third-party libraries from CocoaPods, Maven, and npm.js in their mobile applications without the need for wrappers.

gulp is an open-source JavaScript toolkit, used as a streaming build system in front-end web development.

Grunt is a JavaScript task runner, a tool used to automatically perform frequent tasks such as minification, compilation, unit testing, and linting. It uses a command-line interface to run custom tasks defined in a file. Grunt was created by Ben Alman and is written in Node.js. It is distributed via npm. As of October 2022, there were more than 6,000 plugins available in the Grunt ecosystem.

<span class="mw-page-title-main">Yarn (package manager)</span> JavaScript package manager

Yarn is one of the main JavaScript package managers, developed in 2016 by Sebastian McKenzie of Meta for the Node.js JavaScript runtime environment. An alternative to the npm package manager, Yarn was created as a collaboration of Facebook, Exponent, Google, and Tilde to solve consistency, security, and performance problems with large codebases.

<span class="mw-page-title-main">Deno (software)</span> Secure JavaScript and TypeScript runtime

Deno is a runtime for JavaScript, TypeScript, and WebAssembly that is based on the V8 JavaScript engine and the Rust programming language. Deno was co-created by Ryan Dahl, who also created Node.js.

npm, Inc., is a company founded in 2014. It was acquired by GitHub, a subsidiary of Microsoft, in 2020. The company maintains the npm package manager for Node.js and the npm Registry, which hosts software packages and version control based on Git.

peacenotwar is a piece of malware, which has been characterized as protestware, created by Brandon Nozaki Miller. In March 2022, it was added as a dependency in an update for node-ipc, a common JavaScript dependency.

<span class="mw-page-title-main">Bun (software)</span> JavaScript runtime

Bun is a JavaScript runtime, package manager, test runner and bundler built from scratch using the Zig programming language. It was designed by Jarred Sumner as a drop-in replacement for Node.js. Bun uses WebKit's JavaScriptCore as the JavaScript engine, unlike Node.js and Deno, which both use V8.

On March 22, 2016, Azer Koçulu, a software engineer, removed a project from npm he had published titled left-pad. Koçulu deleted the project following a dispute with Kik which resulted in the company forcibly taking control of a different npm project owned by Koçulu. As a result, thousands of software projects that utilized left-pad as a dependency including the Babel transcompiler and the React web framework were unable to be built or installed.

References

  1. 1 2 "Microsoft-owned GitHub to acquire JavaScript package manager Npm". GeekWire. 17 March 2020.
  2. "Earliest releases of npm". GitHub. Retrieved 5 January 2019.
  3. "Release 10.5.2". 10 April 2024. Retrieved 23 April 2024.
  4. Dierx, Peter (30 March 2016). "A Beginner's Guide to npm – the Node Package Manager". sitepoint. Retrieved 22 July 2016.
  5. npm [@npmjs] (22 August 2011). ""npm" doesn't stand for "Node Package Manager". It stands for "npm Is Not An Acronym". Why not "NINAA"? Because then it would be an acronym" (Tweet). Retrieved 9 November 2023 via Twitter.
  6. Schlueter, Isaac Z. (25 March 2013). "Forget CommonJS. It's dead. **We are server side JavaScript.**". GitHub.
  7. "NPM/Cli". GitHub .
  8. Ellingwood, Justin. "How To Use npm to Manage Node.js Packages on a Linux Server". DigitalOcean. Retrieved 22 October 2016.
  9. "npm-install". docs.npmjs. Retrieved 22 October 2016.
  10. "semver". docs.npmjs. Archived from the original on 3 December 2016. Retrieved 22 October 2016.
  11. "npm-version". docs.npm. Retrieved 29 October 2016.
  12. Koirala, Shivprasad (21 August 2017). "What is the need of package-lock.json in Node?". codeproject.
  13. Ampersand.js. "Ampersand.js – Learn". ampersandjs.com. Retrieved 22 July 2016.
  14. "Critical Linux filesystem permissions are being changed by latest version". GitHub. Retrieved 25 February 2018.
  15. npm. "'npm audit': identify and fix insecure dependencies". The npm Blog. Retrieved 14 August 2018.
  16. npm. "The Node Security Platform service is shutting down 9/30". The npm Blog. Retrieved 14 August 2018.
  17. 1 2 Ojamaa, Andres; Duuna, Karl (2012). "Assessing the Security of Node.js Platform". 2012 International Conference for Internet Technology and Secured Transactions. IEEE. ISBN   978-1-4673-5325-0 . Retrieved 22 July 2016.
  18. Nassri, Ahmad (14 April 2020). "So long, and thanks for all the packages!". The npm Blog. Retrieved 6 January 2021.
  19. "npm Code of Conduct: acceptable package content" . Retrieved 9 May 2017.
  20. Vorbach, Paul. "npm-stat: download statistics for NPM packages". npm-stat.com.
  21. "registry | npm Docs". docs.npmjs.com. Retrieved 10 May 2021.
  22. 1 2 Williams, Chris. "How one developer just broke Node, Babel and thousands of projects in 11 lines of JavaScript". The Register. Retrieved 17 April 2016.
  23. Collins, Keith (27 March 2016). "How one programmer broke the internet by deleting a tiny piece of code". Quartz. Retrieved 23 December 2020.
  24. 1 2 Sharma, Ax (27 July 2022). "Protestware on the rise: Why developers are sabotaging their own code". TechCrunch. Retrieved 11 May 2024.
  25. "How 17 Lines of Code Took Down Silicon Valley's Hottest Startups". HuffPost. 24 March 2016. Retrieved 11 May 2024.
  26. "kik, left-pad, and npm" . Retrieved 9 May 2017.
  27. "changes to unpublish policy". npm Blog (Archive). Retrieved 23 January 2022.
  28. "BIG sabotage: Famous npm package deletes files to protest Ukraine war". Bleeping Computer. Retrieved 17 March 2022.
  29. Juha Saarinen (17 March 2022). "'Protestware' npm package dependency labelled supply-chain attack". IT News. nextmedia.
  30. Proven, Liam (18 March 2022). "JavaScript library updated to wipe files from Russian computers". The Register . Situation Publishing. Archived from the original on 18 March 2022. Retrieved 18 March 2022.
  31. Goodin, Dan (26 November 2018). "Widely used open source software contained bitcoin-stealing backdoor". Ars Technica. Retrieved 11 May 2024.
  32. Claburn, Thomas. "Check your repos... Crypto-coin-stealing code sneaks into fairly popular NPM lib (2m downloads per week)". www.theregister.com. Retrieved 11 May 2024.
  33. Sharma, Ax (2 September 2021). "NPM package with 3 million weekly downloads had a severe vulnerability". Ars Technica. Retrieved 11 May 2024.
  34. Claburn, Thomas. "JavaScript library downloaded 3m times a week exposes apps to hijacking via evil proxy configs". www.theregister.com. Retrieved 11 May 2024.
  35. "Dev corrupts NPM libs 'colors' and 'faker' breaking thousands of apps". Bleeping Computer. Retrieved 9 January 2022.
  36. Burt, Jeff. "Hijacked S3 buckets used in attacks on npm packages". www.theregister.com. Retrieved 11 May 2024.
  37. "Hello, Yarn!". The npm Blog. 11 October 2016. Retrieved 17 December 2016.
  38. "Managing Dependencies". Deno Docs. Retrieved 6 January 2024.
  39. "Node and npm modules | Deno Docs". docs.deno.com. Retrieved 16 January 2024.
  40. Katz, Yehuda (11 October 2016). "Why I'm working on Yarn" . Retrieved 17 December 2016.