OptionalauthorThe “author” is one person.
OptionalbinA map of command name to local file name. On install, npm will symlink that file into prefix/bin for global installs, or ./node_modules/.bin/ for local installs.
OptionalbrowserIf your module is meant to be used client-side the browser field should be used instead of the main field. This is helpful to hint users that it might rely on primitives that aren’t available in Node.js modules. (e.g. window)
OptionalbugsThe url to your project’s issue tracker and / or the email address to which issues should be reported. These are helpful for people who encounter issues with your package.
Optionalcontributors“contributors” is an array of people.
OptionalcpuIf your code only runs on certain cpu architectures, you can specify which ones.
{
"cpu": ["x64", "ia32"]
}
Like the os option, you can also block architectures:
{
"cpu": ["!arm", "!mips"]
}
The host architecture is determined by process.arch
OptionaldependenciesDependencies are specified in a simple object that maps a package name to a version range. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or git URL.
OptionaldescriptionPut a description in it. It’s a string. This helps people discover your package, as it’s listed in npm search.
OptionaldevIf someone is planning on downloading and using your module in their program, then they probably don’t want or need to download and build the external test or documentation framework that you use.
In this case, it’s best to map these additional items in a devDependencies object.
OptionalexportsAlternate and extensible alternative to "main" entry point.
When using {type: "module"}, any ESM module file MUST end with .mjs extension.
Docs:
OptionalfilesThe optional files field is an array of file patterns that describes the entries to be included when your package is installed as a dependency. File patterns follow a similar syntax to .gitignore, but reversed: including a file, directory, or glob pattern (*, **/*, and such) will make it so that file is included in the tarball when it’s packed. Omitting the field will make it default to ["*"], which means it will include all files.
OptionalfundingAn object containing a URL that provides up-to-date information about ways to help fund development of your package, a string URL, or an array of objects and string URLs
OptionalhomepageThe url to the project homepage.
OptionalimportsOptionalkeywordsPut keywords in it. It’s an array of strings. This helps people discover your package as it’s listed in npm search.
OptionallicenseYou should specify a license for your package so that people know how they are permitted to use it, and any restrictions you’re placing on it.
OptionalmainThe main field is a module ID that is the primary entry point to your program. That is, if your package is named foo, and a user installs it, and then does require("foo"), then your main module’s exports object will be returned.
This should be a module ID relative to the root of your package folder.
For most modules, it makes the most sense to have a main script and often not much else.
OptionalmanSpecify either a single file or an array of filenames to put in place for the man program to find.
OptionalmoduleNon-Standard Node.js alternate entry-point to main. An initial implementation for supporting CJS packages (from main), and use module for ESM modules.
OptionalnameThe name is what your thing is called. Some rules:
OptionaloptionalIf a dependency can be used, but you would like npm to proceed if it cannot be found or fails to install, then you may put it in the optionalDependencies object. This is a map of package name to version or url, just like the dependencies object. The difference is that build failures do not cause installation to fail.
OptionalosYou can specify which operating systems your module will run on:
{
"os": ["darwin", "linux"]
}
You can also block instead of allowing operating systems, just prepend the blocked os with a '!':
{
"os": ["!win32"]
}
The host operating system is determined by process.platform
It is allowed to both block and allow an item, although there isn't any good reason to do this.
OptionalpackageSee: https://nodejs.org/api/packages.html#packagemanager
This field defines which package manager is expected to be used when working on the current project.
Should be of the format: <name>@<version>[#hash]
OptionalpeerIn some cases, you want to express the compatibility of your package with a host tool or library, while not necessarily doing a require of this host. This is usually referred to as a plugin. Notably, your module may be exposing a specific interface, expected and specified by the host documentation.
OptionalprivateIf you set "private": true in your package.json, then npm will refuse to publish it.
OptionalpublishThis is a set of config values that will be used at publish-time.
Optionalaccess?: "public" | "restricted"The access level that will be used if the package is published.
Optionaldirectory?: stringpnpm-only
You also can use the field publishConfig.directory to customize
the published subdirectory relative to the current package.json.
It is expected to have a modified version of the current package in the specified directory (usually using third party build tools).
OptionalexecutableFiles?: string[]pnpm-only
By default, for portability reasons, no files except those listed in the bin field will be marked as executable in the resulting package archive. The executableFiles field lets you declare additional fields that must have the executable flag (+x) set even if they aren't directly accessible through the bin field.
OptionallinkDirectory?: booleanpnpm-only
When set to true, the project will be symlinked from the
publishConfig.directory location during local development.
Optionalregistry?: stringThe registry that will be used if the package is published.
Optionaltag?: stringThe tag that will be used if the package is published.
OptionalrepositorySpecify the place where your code lives. This is helpful for people who want to contribute. If the git repo is on GitHub, then the npm docs command will be able to find you.
For GitHub, GitHub gist, Bitbucket, or GitLab repositories you can use the same shortcut syntax you use for npm install:
Optionaldirectory?: stringIf the package.json for your package is not in the root directory (for example if it is part of a monorepo), you can specify the directory in which it lives:
OptionalscriptsThe scripts field is a dictionary containing script commands that are run at various times in the lifecycle of your package.
OptionaltypeMake main entry-point be loaded as an ESM module, support "export" syntax instead of "require"
Docs:
OptionaltypesTypeScript typings, typically ending by .d.ts.
OptionaltypesThe field is used to specify different TypeScript declaration files for different versions of TypeScript, allowing for version-specific type definitions.
OptionaltypingsThis field is synonymous with types.
OptionalunpkgThe unpkg field is used to specify the URL to a UMD module for your package. This is used by default in the unpkg.com CDN service.
OptionalversionVersion must be parseable by node-semver, which is bundled with npm as a dependency. (npm install semver to use it yourself.)
OptionalworkspacesThe field is used to define a set of sub-packages (or workspaces) within a monorepo.
This field is an array of glob patterns or an object with specific configurations for managing multiple packages in a single repository.
Optionalnohoist?: string[]Packages to block from hoisting to the workspace root. Uses glob patterns to match module paths in the dependency tree.
Docs:
Optionalpackages?: string[]Workspace package paths. Glob patterns are supported.
Defines a PackageJson structure.
Param: pkg
The
package.jsoncontent as an object. See PackageJson.Returns
the same
package.jsonobject.