What is NPM?
NPM is a package manager for Node.js packages, or modules if you like.
www.npmjs.com hosts thousands of free packages to download and use.
Npmhu
The NPM program is installed on your computer when you install Node.js
What is a Package?
- To publish to a scope, you can either: Change the name to @username/package-name manually in package.json. Run npm init -scope=username instead of npm init. If your repository has a scope, you need to adjust the publish command slightly: npm publish -access public. That’s all you need to do to publish a package to npm.
- Npm install -production. Install everything in package.json, except devDependecies. Npm install lodash. Install a package. Npm install -save-dev lodash. Install as devDependency. Npm install -save-exact lodash. Install with exact.save is the default as of npm@5.
Downloading and installing Node.js and npm. To publish and install packages to and from the public npm registry or your company's npm Enterprise registry, you must install Node.js and the npm command line interface using either a Node version manager or a Node installer. We strongly recommend using a Node version manager like nvm to install.
A package in Node.js contains all the files you need for a module.
Modules are JavaScript libraries you can include in your project.
Download a Package
Downloading a package is very easy.
Open the command line interface and tell NPM to download the package you want.
I want to download a package called 'upper-case':
Download 'upper-case':
Now you have downloaded and installed your first package!
NPM creates a folder named 'node_modules', where the package will be placed. All packages you install in the future will be placed in this folder.
My project now has a folder structure like this:
C:UsersMy Namenode_modulesupper-case
Using a Package
Once the package is installed, it is ready to use.
Include the 'upper-case' package the same way you include any other module:
Create a Node.js file that will convert the output 'Hello World!' into upper-case letters:
Example
var uc = require('upper-case');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(uc.upperCase('Hello World!'));
res.end();
}).listen(8080);
Save the code above in a file called 'demo_uppercase.js', and initiate the file:
Initiate demo_uppercase:
If you have followed the same steps on your computer, you will see the same result as the example: http://localhost:8080
Last December, GitHub recognized that it hadn't revisited the dispute policy for npm packages since acquiring NPM in March, 2020, and in February this year, it suspended transfers of abandoned packages until it could come up with a system that's fair, consistent, and enforceable.
The Microsoft-owned company did so because Andrew Sampson, CEO and co-founder of streaming app Rainway, showed that npm's process was none of those things.
Sampson and other contributors created an open source, cross-platform serialization format called Bebop to support the Rainway app. To ensure the chosen name remained the same across multiple programming languages, they proceeded to register the Bebop package name at various package registries like .Net's NuGet, Rust's Cargo, and Dart's pub.dev.
The name, however, was taken on npm, the registry frequented by JavaScript, Node.js, and TypeScript developers. At the time, npm's advice for handling module name disputes was to email the owner of the relevant package and to send a copy of the message to npm's support address.
'After a few weeks, if there's no resolution, we'll sort it out,' the now removed dispute policy explains.
Sampson emailed the listed address, got no response, and four weeks later was rewarded with a note from npm giving over control of the Bebop name.
Bad management
Github's npm team shouldn't have done so because the registry had the wrong email address for the individual who had registered Bebop and had been using it for more than eight years.
'As it turns out, the package was not abandoned,' explained Sampson via Twitter. '[Zach Kelling] published it over eight years ago and used it consistently in that time.'
According to Sampson, none of the emails associated with Kelling's account received the name inquiry and the email address produced by the command npm owner ls bebop
wasn't associated with the package.
'Zach only noticed the ownership had been taken away from his account because an update failed to publish,' said Sampson.
Sampson said Kelling opened a ticket with npm support and was told the name would not be returned, but was offered a GitHub Pro subscription and a $100 credit for GitHub merch 'for the inconvenience.'
'We take our role as stewards of the registry very seriously,' a GitHub spokesperson said in an email to The Register. 'We are not currently accepting dispute requests to 'adopt an abandoned package' as we re-evaluate and update the overall dispute process, which we’re tracking in our Public Roadmap.'
Kelling did not immediately respond to a request for comment.
All wrapped up
Npma Forms Online
Sampson personally ended up compensating Kelling for the name after getting in contact. And Kelling subsequently renamed his original Bebop package 'bebop-cli.'
Sampson nonetheless expressed concern that the NuGet community is currently trying to implement a similar process for taking over package names and fears it will have the same problems.
'Package adoption creates new avenues for compromising supply chains – registries should not be facilitating it,' was the warning. 'If a package transfer does need to occur, then the only method to do so should be the owner doing it. The registry itself shouldn't have the ability.'
In an email to The Register, Sampson expressed sympathy for GitHub and npm, acknowledging package management and registry operation are both difficult.
'I think mistakes are inevitable at the scale of something like npm,' Sampson said. 'That being said, their response to the developer that was impacted by their mistake was pretty awful. That is why we ended up paying him $5,000 because I understand that for a developer time is their most valuable commodity, and the undue stress and disruption caused by their mistake likely hampered them for a few days.'
Sampson expressed pleasure that npm suspended its transfer process as a result of the incident and noted that the support rep in communications dealt with mentioned that previous incidents of this sort had already prompted changes in npm's processes.
Transfers of control over package names at npm have proven problematic in the past, as the 2019 PureScript incident demonstrates. Other package registries have encountered similar issues.
The Java ecosystem, like some others, has dealt with potential name conflicts through hierarchical namespaces. For example, a Java program will reference com.example.library_name.package_name
, as opposed to just package_name
. This offers an obvious way to avoid identical package names.
But that convention isn't adopted everywhere and in programming ecosystems that accommodate flat namespaces like 'bebop,' names accrue brand value as they become popular or just because they're short and memorable. That has the potential to incentivize abuse like name squatting and to encourage developers to take steps to capture, control, and perhaps speculate on 'great names.'
Www.npmhu.org
'I think it is a hard problem to solve,' said Sampson. 'Should a package name be lost forever simply because someone registered it over a decade ago and never actually used it? What happens if the owner of a popular package dies and they never assigned other primary contributors, is a fork now forced by the community? There is a lot of nuance involved here. People much smarter than me will figure out a system that works – that is the beauty of open source.' ®