'Maven' behavior for npm | packages.json

Want to know what is the package.json file that appears everywhere in the project?

package.json is a file used to manage local dependencies. There are many benefits to using package.json.
It can be used as a documentation for your project's dependencies.
It is used to specify the version number of the dependencies used in your project.
It makes it easier for you to share your projects with other developers.

The composition of

package.json The contents that must be included in the package.json file are:

1."name"
1)all lowercase
2)one word, no spaces
3)dashes and underscores allowed

2."version"
1)in the form of x.x.x
2)follows (semver spec)[[https://docs.npmjs.com/getting-started/semantic-versioning](https://docs.npmjs.com/getting-started/semantic-versioning)]



Create a package.json

Using the initialization tool provided by npm can easily create a package.json file

npm init

Then fill in the corresponding items according to the prompts.

name: defaults to author name unless in a git directory, in which case it will be the name of the repository
version: always 1.0.0
main: always index.js
scripts: by default creates a empty test script
keywords: empty
author: whatever you provided the CLI
license: ISC
repository: will pull in info from the current directory, if present
bugs: will pull in info from the current directory, if present
homepage: will pull in info from the current directory, if present


You can also use the initialization command line to initialize some parameters

> npm set init.author.email "[email protected]"
> npm set init.author.name "s"
> npm set init.license "BAC"



Note: If there is nothing in the package.json file in the project, npm will use the first line in README.md instead. The description of the package.json file can facilitate others to look up the packages your project depends on, and greatly facilitate your management of your own project.

Specifying Dependencies

In order to specify the dependencies you apply to your project, you need to list them in the packages.json file. There are two types of dependencies that need to be listed.

"dependencies": here lists the dependencies that need to be used in the application of your product;
"devDependencies": here lists the dependencies used in development and testing.
These two properties can be edited manually in the package.json file, or they can be automatically added to the file using command line arguments when installing these packages.
Add a command to "dependencies":
npm install <package_name> --save
Add a command to "devDependencies":
npm install <package_name> --save-dev

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326342363&siteId=291194637