Search

what is package.json

  • Share this:

`package.json` is a file that is used to manage the dependencies of a JavaScript project. It is typically located at the root of a project and contains metadata about the project, including the project's name, version, and a list of the packages that the project depends on.

Here is an example of a `package.json` file:

{
  "name": "my-project",
  "version": "1.0.0",
  "dependencies": {
    "react": "^16.13.1",
    "lodash": "^4.17.19",
    "axios": "^0.21.0"
  },
  "devDependencies": {
    "eslint": "^7.5.0",
    "jest": "^26.0.1"
  },
  "scripts": {
    "start": "node index.js",
    "test": "jest"
  }
}

The `dependencies` field lists the packages that are required for the project to run in production. The `devDependencies` field lists the packages that are only needed for development, such as testing and linting tools. The `scripts` field lists commands that can be run from the command line using `npm run`.

To install the dependencies listed in a `package.json` file, you can run the `npm install` command. This will download and install all of the packages listed in the `dependencies` and `devDependencies` fields and save them to the `node_modules` directory.

You can also use the `npm install` command to install a package and add it to the `dependencies` field of the `package.json` file, like this:

npm install express --save

This will install the `express` package and add it to the `dependencies` field in the `package.json` file.

 

About author
I am a professional web developer. I love programming and coding, and reading books. I am the founder and CEO of StorialTech.