package.json configuration
Sraban Pahadasingh June 22, 2024 06:03 PMThe most common fields and configurations found in package.json. Depending on the project's needs and tooling used, some of these configurations may not be present or may have additional custom configurations.
-
name: The name of the package or project.
-
version: The version of the package or project, following Semantic Versioning (SemVer).
-
description: A brief description of the package or project.
-
keywords: An array of keywords that describe the package, useful for search optimization.
-
homepage: The URL to the project's homepage.
-
bugs: Information about where to report bugs for the package.
-
license: The license under which the package is distributed.
-
author: The name and email address of the package author.
-
contributors: An array of contributors to the project.
-
files: An array of files to include in the package.
-
main: The entry point of the package (the main module that gets executed when the package is required).
-
browser: Replacement files to use in the browser environment.
-
bin: Specifies command-line commands that are installed with the package.
-
scripts: An object where each key is a script name and the value is the command to run for that script.
-
dependencies: An object listing the packages that the project depends on in production.
-
devDependencies: An object listing packages that are only needed for development and testing.
-
peerDependencies: An object listing packages that the project expects the host environment to provide.
-
optionalDependencies: An object listing packages that are optional dependencies.
-
engines: Specifies the versions of Node.js and npm that the package is compatible with.
-
os: An array of operating systems on which the package runs.
-
cpu: An array of CPUs that the package runs on.
-
private: If true, prevents the package from being accidentally published to the npm registry.
-
publishConfig: Configures publishing options when using npm publish.
-
directories: Specifies a directory structure for the package.
-
repository: The URL and type of source control repository for the package.
-
scripts: Custom scripts that can be run with npm, typically used for build, test, and other automation tasks.
-
config: Configuration parameters that can be used by the scripts.
-
workspaces: An array of workspace packages that are part of a multi-package repository.
-
jest (or other test runner configurations): Specific configurations for test runners like Jest.
- eslintConfig (or other linter configurations): Configuration for linters like ESLint.
ex.
{
"name": "my-node-project",
"version": "1.0.0",
"description": "A sample Node.js project",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "jest"
},
"dependencies": {
"express": "^4.17.2"
},
"devDependencies": {
"jest": "^27.0.0"
},
"author": "Your Name",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/your-username/my-node-project.git"
},
"bugs": {
"url": "https://github.com/your-username/my-node-project/issues"
},
"homepage": "https://github.com/your-username/my-node-project#readme"
}