---
# System prepended metadata

title: npm 使用心得
tags: [npm]

---

npm 使用心得
===

基本上有安裝過 node.js 就可以使用 npm

假設想安裝 jQuery 就下指令
```bash=
npm install jquery 
```
![](https://i.imgur.com/QTBhpOV.png)


## 一次安裝多個套件
透過指令
```bash=
npm init
```
可以產生 package.json 內容如下:point_down:
```json=
{
  "name": "sam",
  "version": "1.0.0",
  "description": "npm init",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

```
只要下過安裝套件指令，例如:安裝 jQuery
```bash=
npm install jquery 
```
![](https://i.imgur.com/KIErywb.png)
package.json 內就會記錄在 dependencies 欄位上
```json=
{
  "name": "sam",
  "version": "1.0.0",
  "description": "npm init",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "jquery": "^3.5.1"
  }
}
```
只後只要帶著　package.json　就能透過指令一次安裝所有套件
```bash=
npm install
```
![npm install](https://i.imgur.com/PcynLFA.png)




## 參考資料
[Node.js 系列學習日誌 #6 - 使用 package.json 安裝、管理模組](https://ithelp.ithome.com.tw/articles/10158140)

###### tags: `npm`