The best way to manage locally installed npm packages is to create a package.json file.
package.json file offers a lot of benefits:
It serves as documentation for the packages your project depends on. It allows you to specify the version of a package that your project can use using semantic versioning rules. Making your build reproducible means it's easier to share with other developers in a way that is easier to share. requirements
At a minimum, package.json must have:
"name" all lowercase one word, no spaces dashes and underscores allowed "version" in the form of x.x.x follows semver spec
For example:
Create package.json
To create a package.json run:
> npm init This will launch a command-line questionnaire and will finally create a package.json in the directory where you launched the command.
Initializing a package.json by running npm init in the directory will let you enter a lot of information, such as: name, version, author, etc.
If we use the default name, just press enter!!
I only entered the information in the description and author, and all other returns are default, for example:
We can see that the generated package.json package is as follows:
If you want to use the default generation and don't want to hit the car enter button every time, you can add --yes after npm init,
Code:
This way, you don't have to hit the enter button every time, and the result is as follows:
name: defaults to the author name, unless in the git directory, in which case it will be the name of the repository version:always 1.0.0 main: always index.js scrip{filter}ts: Creates an empty test script by default keywords: empty author: whatever CLI you provide license:ISC repository: will extract information from the current directory (if it exists). bugs: Information will be extracted from the current directory (if it exists). homepage: will extract information from the current directory (if it exists).
You can also set several configuration options for the init command. Some useful:
|