The build, bundle and cache commands
In our previous tutorial we looked at the audit, bin and bugs cli commands, in this tutorial we will examine how the npm-build, npm-bundle and npm-cache work.
The npm build is used to build a package, the synopsis is given in the next section.
npm build [<package-folder>]
where <package-folder> is a folder that contains a package.json in its root.
This is the plumbing command that is called by npm link and npm install.
Generally, this command is called during installation, however, if you need to run it directly, you can run:
npm run-script build
The npm-bundle command has been removed. Npm removed the command as from v1.0, the reason behind the removal is that the default behavior now is to install packages into the local space.
Hence, you should just use the npm install to do what the npm bundle used to do.
The npm cache is used to manipulate the cache of packages.
npm cache add <tarball file> npm cache add <folder> npm cache add <tarball url> npm cache add <name>@<version> npm cache clean [<path>] aliases: npm cache clear, npm cache rm npm cache verify
The npm-cache cli command is used to add, list, or clean the npm cache folder.
- add: You use this to add the specified package to the local cache. This command is primarily intended to be used by npm internally, but it can equally provide a way to add data to the local installation cache explicitly.
- clean: it can also be used to delete all data out of the cache folder.
- verify: Finally, it can verify the contents of the cache folder, garbage collecting any data that is not needed, and verifies the integrity of the cache index and all the cached data.
npm will store cache data in an opaque directory within the configured cache, that is named _cacache. This directory is a cacache-based content-addressable cache that will store all http request data as well as other package-related data. The primary way to access this directory is through the pacote, which is the library responsible for all package fetching as of npm@5.
All the data that passes through the cache is fully verified for integrity on both insertion and extraction. Cache corruption either triggers an error, or signals to pacote that the data has to be refetched, which it does automatically. This is why it is expected you never have to clear the cache for any reason aside reclaiming disk space, this explains why clean now requires --force to run.
Currently there is no method exposed through npm to inspect or directly manage the contents of this cache. If you have to access it, you have to used cacache directly.
npm does not remove data by itself: the cache grows as new packages are installed.
A NOTE ON THE CACHE'S DESIGN
The npm cache is a cache and nothing more: You should not rely on it as a persistent and reliable data store for package data. npm cannot guarantee that a previously-cached piece of data will be available later, also, npm automatically deletes corrupted contents. The primary guarantee that the cache makes is that, when it does return data, that data will be exactly the data that was inserted into it.
If you want to run an offline verification of existing cache contents, you should use npm cache verify.
This is the root cache folder.
Default: ~/.npm on Posix, or %AppData%/npm-cache on Windows.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join