This article is a mirror article of machine translation, please click here to jump to the original article.

View: 8572|Reply: 0

npm tutorial (5): How to use package.json tutorial

[Copy link]
Posted on 12/13/2017 2:04:19 PM | | | |
The best way to manage locally installed npm packages is to create a package.json file.

A package.json file offers you a lot of great things:

It serves as documentation for the packages your project depends on.
It allows you to specify the version of the package that your project can use using semantic version rules.
It makes your builds repeatable, which means it's easier to share with other developers.
requirements

At the very least,package.json must have

“name”: All lowercase, no spaces, dashes and underscores allowed
“version”: in the form of x.x.x, following the semver specification

For example:


Create a package.json





This will launch a command-line questionnaire and finally create a package.json in the directory where you launched the command.

You can get a default package.json by running npm init with the --yes or -y flag:



This will not ask any questions and instead generate a default package.json using the information extracted from the current directory.

name: The name of the current directory
version: always 1.0.0
descrip{filter}tion: information in the readme, otherwise an empty string ""
main: always index.js
scrip{filter}ts: Creates an empty test script by default
keywords: empty
author: empty
license:ISC
Bugs: Information from the current directory (if present)
homepage: information from the current directory (if it exists)
You can also set several configuration options for the init command. Some useful:




(You need to delete package.json file, regenerate it before you can change it, if you don't delete it, it won't be automatically replaced or overwritten!) )

Note:

If there is no description field in the package.json, npm uses the first line of the README.md or README instead. This description can help people find your package in npm searches, so it's very useful to make a custom description in the package.json to make your package more discoverable.





Previous:npm tutorial (4): Install npm packages locally
Next:mysqldump imports and exports database summaries
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com