官术网_书友最值得收藏!

The package.json file

We know how to download a package and how to import it into our project. However, we will commonly need more than one package, with some specific versions. Should we memorize them to download manually each time we set up the project? No, now is the moment to create a package.json file.

This file is not only to map our dependencies; it must contain all the metadata about our project, and it serves as a quick documentation for which packages your project depends on. As minimal, the package.json should contain the following:

  • Name: Project name, all lowercase with no blank spaces (you can use underscores if needed)
  • Version: In the form of x.x.x

We can create this file manually, but NPM allows us to create it automatically by executing the following command:

$ npm init

The preceding command will prompt you with a bunch of questions that will be present in your package.json file. If you don't want to accept the defaults without being prompted any question, run the same command, adding a --yes flag at the end:

$ npm init --yes

Then, you will get a package.json file, as follows:

{
"name": "my_package",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/package_owner/my_package.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/package_owner/my_package/issues"
},
"homepage": "https://github.com/package_owner/my_package"
}
主站蜘蛛池模板: 承德县| 金阳县| 理塘县| 阿巴嘎旗| 永安市| 郧西县| 桃江县| 南华县| 子洲县| 涪陵区| 沂水县| 海伦市| 定襄县| 敦煌市| 苗栗县| 蒙山县| 阿拉善左旗| 宁波市| 循化| 周至县| 商南县| 柳州市| 苍南县| 庄浪县| 灵石县| 航空| 瑞金市| 承德县| 林州市| 苗栗市| 枣庄市| 宁津县| 和田市| 南汇区| 合水县| 拜泉县| 诸城市| 扶沟县| 和龙市| 沅陵县| 银川市|