網頁

2019/5/21

NPM npm init指令作用

NPM的npm init指令的作用如下。

npm init指令會將所在目錄設為npm package,也就是會新增一個package.json

例如在Window的cmd命令提示字元執行如下。

D:\mynode\demo>npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install ` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (demo) demo
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to D:\mynode\demo\package.json:

{
  "name": "demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Is this OK? (yes) yes

建立好的package.json的預設內容如下。

{
  "name": "demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

package.json的內容包括專案依賴套件的設定(dependencies),測試(test)及建構(build)專案的腳本(scripts)等。


如果你是Java工程師,NPM就如同Maven,package.json的角色就如同Maven的pom.xml


參考:

沒有留言:

張貼留言