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

View: 8633|Reply: 0

node.js initialize with package.json

[Copy link]
Posted on 12/14/2016 11:03:04 AM | | | |
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:











Previous:What is npm? What is npm?
Next:15 good. .NET
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