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

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"
}
主站蜘蛛池模板: 凤庆县| 怀柔区| 曲阳县| 华容县| 昭通市| 普宁市| 泾源县| 天气| 临海市| 浑源县| 吕梁市| 柳州市| 闽侯县| 无极县| 东山县| 怀化市| 墨竹工卡县| 遂昌县| 红桥区| 茌平县| 泰州市| 韶山市| 合水县| 沈阳市| 新田县| 绥阳县| 曲阳县| 开鲁县| 特克斯县| 金湖县| 沽源县| 台北县| 简阳市| 涞水县| 信丰县| 方山县| 宁国市| 稷山县| 聊城市| 乌鲁木齐县| 和平县|