codekingpro/portable-devtools
114k
1.TH "NPM-DIFF" "1" "April 2026" "NPM@11.13.0" ""
2.SH "NAME"
3\fBnpm-diff\fR - The registry diff command
4.SS "Synopsis"
5.P
6.RS 2
7.nf
8npm diff \[lB]...<paths>\[rB]
9.fi
10.RE
11.SS "Description"
12.P
13Similar to its \fBgit diff\fR counterpart, this command will print diff patches of files for packages published to the npm registry.
14.RS 0
15.IP \(bu 4
16\fBnpm diff --diff=<spec-a> --diff=<spec-b>\fR
17.P
18Compares two package versions using their registry specifiers, e.g: \fBnpm diff --diff=pkg@1.0.0 --diff=pkg@^2.0.0\fR. It's also possible to compare across forks of any package, e.g: \fBnpm diff --diff=pkg@1.0.0 --diff=pkg-fork@1.0.0\fR.
19.P
20Any valid spec can be used, so that it's also possible to compare directories or git repositories, e.g: \fBnpm diff --diff=pkg@latest --diff=./packages/pkg\fR
21.P
22Here's an example comparing two different versions of a package named \fBabbrev\fR from the registry:
23.P
24.RS 2
25.nf
26npm diff --diff=abbrev@1.1.0 --diff=abbrev@1.1.1
27.fi
28.RE
29.P
30On success, output looks like:
31.P
32.RS 2
33.nf
34diff --git a/package.json b/package.json
35index v1.1.0..v1.1.1 100644
36--- a/package.json
37+++ b/package.json
38@@ -1,6 +1,6 @@
39 {
40 "name": "abbrev",
41- "version": "1.1.0",
42+ "version": "1.1.1",
43 "description": "Like ruby's abbrev module, but in js",
44 "author": "Isaac Z. Schlueter <i@izs.me>",
45 "main": "abbrev.js",
46.fi
47.RE
48.P
49Given the flexible nature of npm specs, you can also target local directories or git repos just like when using \fBnpm install\fR:
50.P
51.RS 2
52.nf
53npm diff --diff=https://github.com/npm/libnpmdiff --diff=./local-path
54.fi
55.RE
56.P
57In the example above we can compare the contents from the package installed from the git repo at \fBgithub.com/npm/libnpmdiff\fR with the contents of the \fB./local-path\fR that contains a valid package, such as a modified copy of the original.
58.IP \(bu 4
59\fBnpm diff\fR (in a package directory, no arguments):
60.P
61If the package is published to the registry, \fBnpm diff\fR will fetch the tarball version tagged as \fBlatest\fR (this value can be configured using the \fBtag\fR option) and proceed to compare the contents of files present in that tarball, with the current files in your local file system.
62.P
63This workflow provides a handy way for package authors to see what package-tracked files have been changed in comparison with the latest published version of that package.
64.IP \(bu 4
65\fBnpm diff --diff=<pkg-name>\fR (in a package directory):
66.P
67When using a single package name (with no version or tag specifier) as an argument, \fBnpm diff\fR will work in a similar way to \fB\[rs]fBnpm-outdated\[rs]fR\fR \fI\(lanpm-outdated\(ra\fR and reach for the registry to figure out what current published version of the package named \fB<pkg-name>\fR will satisfy its dependent declared semver-range. Once that specific version is known \fBnpm diff\fR will print diff patches comparing the current version of \fB<pkg-name>\fR found in the local file system with that specific version returned by the registry.
68.P
69Given a package named \fBabbrev\fR that is currently installed:
70.P
71.RS 2
72.nf
73npm diff --diff=abbrev
74.fi
75.RE
76.P
77That will request from the registry its most up to date version and will print a diff output comparing the currently installed version to this newer one if the version numbers are not the same.
78.IP \(bu 4
79\fBnpm diff --diff=<spec-a>\fR (in a package directory):
80.P
81Similar to using only a single package name, it's also possible to declare a full registry specifier version if you wish to compare the local version of an installed package with the specific version/tag/semver-range provided in \fB<spec-a>\fR.
82.P
83An example: assuming \fBpkg@1.0.0\fR is installed in the current \fBnode_modules\fR folder, running:
84.P
85.RS 2
86.nf
87npm diff --diff=pkg@2.0.0
88.fi
89.RE
90.P
91It will effectively be an alias to \fBnpm diff --diff=pkg@1.0.0 --diff=pkg@2.0.0\fR.
92.IP \(bu 4
93\fBnpm diff --diff=<semver-a> \[lB]--diff=<semver-b>\[rB]\fR (in a package directory):
94.P
95Using \fBnpm diff\fR along with semver-valid version numbers is a shorthand to compare different versions of the current package.
96.P
97It needs to be run from a package directory, such that for a package named \fBpkg\fR running \fBnpm diff --diff=1.0.0 --diff=1.0.1\fR is the same as running \fBnpm diff --diff=pkg@1.0.0 --diff=pkg@1.0.1\fR.
98.P
99If only a single argument \fB<version-a>\fR is provided, then the current local file system is going to be compared against that version.
100.P
101Here's an example comparing two specific versions (published to the configured registry) of the current project directory:
102.P
103.RS 2
104.nf
105npm diff --diff=1.0.0 --diff=1.1.0
106.fi
107.RE
108.RE 0
109
110.P
111Note that tag names are not valid \fB--diff\fR argument values, if you wish to compare to a published tag, you must use the \fBpkg@tagname\fR syntax.
112.SS "Filtering files"
113.P
114It's possible to also specify positional arguments using file names or globs pattern matching in order to limit the result of diff patches to only a subset of files for a given package, e.g:
115.P
116.RS 2
117.nf
118npm diff --diff=pkg@2 ./lib/ CHANGELOG.md
119.fi
120.RE
121.P
122In the example above the diff output is only going to print contents of files located within the folder \fB./lib/\fR and changed lines of code within the \fBCHANGELOG.md\fR file.
123.SS "Configuration"
124.SS "\fBdiff\fR"
125.RS 0
126.IP \(bu 4
127Default:
128.IP \(bu 4
129Type: String (can be set multiple times)
130.RE 0
131
132.P
133Define arguments to compare in \fBnpm diff\fR.
134.SS "\fBdiff-name-only\fR"
135.RS 0
136.IP \(bu 4
137Default: false
138.IP \(bu 4
139Type: Boolean
140.RE 0
141
142.P
143Prints only filenames when using \fBnpm diff\fR.
144.SS "\fBdiff-unified\fR"
145.RS 0
146.IP \(bu 4
147Default: 3
148.IP \(bu 4
149Type: Number
150.RE 0
151
152.P
153The number of lines of context to print in \fBnpm diff\fR.
154.SS "\fBdiff-ignore-all-space\fR"
155.RS 0
156.IP \(bu 4
157Default: false
158.IP \(bu 4
159Type: Boolean
160.RE 0
161
162.P
163Ignore whitespace when comparing lines in \fBnpm diff\fR.
164.SS "\fBdiff-no-prefix\fR"
165.RS 0
166.IP \(bu 4
167Default: false
168.IP \(bu 4
169Type: Boolean
170.RE 0
171
172.P
173Do not show any source or destination prefix in \fBnpm diff\fR output.
174.P
175Note: this causes \fBnpm diff\fR to ignore the \fB--diff-src-prefix\fR and \fB--diff-dst-prefix\fR configs.
176.SS "\fBdiff-src-prefix\fR"
177.RS 0
178.IP \(bu 4
179Default: "a/"
180.IP \(bu 4
181Type: String
182.RE 0
183
184.P
185Source prefix to be used in \fBnpm diff\fR output.
186.SS "\fBdiff-dst-prefix\fR"
187.RS 0
188.IP \(bu 4
189Default: "b/"
190.IP \(bu 4
191Type: String
192.RE 0
193
194.P
195Destination prefix to be used in \fBnpm diff\fR output.
196.SS "\fBdiff-text\fR"
197.RS 0
198.IP \(bu 4
199Default: false
200.IP \(bu 4
201Type: Boolean
202.RE 0
203
204.P
205Treat all files as text in \fBnpm diff\fR.
206.SS "\fBglobal\fR"
207.RS 0
208.IP \(bu 4
209Default: false
210.IP \(bu 4
211Type: Boolean
212.RE 0
213
214.P
215Operates in "global" mode, so that packages are installed into the \fBprefix\fR folder instead of the current working directory. See npm help folders for more on the differences in behavior.
216.RS 0
217.IP \(bu 4
218packages are installed into the \fB{prefix}/lib/node_modules\fR folder, instead of the current working directory.
219.IP \(bu 4
220bin files are linked to \fB{prefix}/bin\fR
221.IP \(bu 4
222man pages are linked to \fB{prefix}/share/man\fR
223.RE 0
224
225.SS "\fBtag\fR"
226.RS 0
227.IP \(bu 4
228Default: "latest"
229.IP \(bu 4
230Type: String
231.RE 0
232
233.P
234If you ask npm to install a package and don't tell it a specific version, then it will install the specified tag.
235.P
236It is the tag added to the package@version specified in the \fBnpm dist-tag
237add\fR command, if no explicit tag is given.
238.P
239When used by the \fBnpm diff\fR command, this is the tag used to fetch the tarball that will be compared with the local files by default.
240.P
241If used in the \fBnpm publish\fR command, this is the tag that will be added to the package submitted to the registry.
242.SS "\fBworkspace\fR"
243.RS 0
244.IP \(bu 4
245Default:
246.IP \(bu 4
247Type: String (can be set multiple times)
248.RE 0
249
250.P
251Enable running a command in the context of the configured workspaces of the current project while filtering by running only the workspaces defined by this configuration option.
252.P
253Valid values for the \fBworkspace\fR config are either:
254.RS 0
255.IP \(bu 4
256Workspace names
257.IP \(bu 4
258Path to a workspace directory
259.IP \(bu 4
260Path to a parent workspace directory (will result in selecting all workspaces within that folder)
261.RE 0
262
263.P
264When set for the \fBnpm init\fR command, this may be set to the folder of a workspace which does not yet exist, to create the folder and set it up as a brand new workspace within the project.
265.P
266This value is not exported to the environment for child processes.
267.SS "\fBworkspaces\fR"
268.RS 0
269.IP \(bu 4
270Default: null
271.IP \(bu 4
272Type: null or Boolean
273.RE 0
274
275.P
276Set to true to run the command in the context of \fBall\fR configured workspaces.
277.P
278Explicitly setting this to false will cause commands like \fBinstall\fR to ignore workspaces altogether. When not set explicitly:
279.RS 0
280.IP \(bu 4
281Commands that operate on the \fBnode_modules\fR tree (install, update, etc.) will link workspaces into the \fBnode_modules\fR folder. - Commands that do other things (test, exec, publish, etc.) will operate on the root project, \fIunless\fR one or more workspaces are specified in the \fBworkspace\fR config.
282.RE 0
283
284.P
285This value is not exported to the environment for child processes.
286.SS "\fBinclude-workspace-root\fR"
287.RS 0
288.IP \(bu 4
289Default: false
290.IP \(bu 4
291Type: Boolean
292.RE 0
293
294.P
295Include the workspace root when workspaces are enabled for a command.
296.P
297When false, specifying individual workspaces via the \fBworkspace\fR config, or all workspaces via the \fBworkspaces\fR flag, will cause npm to operate only on the specified workspaces, and not on the root project.
298.P
299This value is not exported to the environment for child processes.
300.SH "SEE ALSO"
301.RS 0
302.IP \(bu 4
303npm help outdated
304.IP \(bu 4
305npm help install
306.IP \(bu 4
307npm help config
308.IP \(bu 4
309npm help registry
310.RE 0
311 