> For the complete documentation index, see [llms.txt](https://stb11816.gitbook.io/python_note/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stb11816.gitbook.io/python_note/ubuntu/nodejs-and-npm.md).

# nodejs & npm

## nodejs & npm

```
# nodejs or nodejs-legacy 選一個
sudo apt install nodejs
sudo apt install nodejs-legacy

# 初步安裝
sudo apt install npm

# 檢視版本
npm -v

# 更新為最新版
sudo npm install npm@latest -g
```

## n

```
# 安裝模組n (負責安裝node的套件)
sudo npm install -g n

# 擇其一
# 安装官方最新版本
sudo n latest
# 安装官方稳定版本
sudo n stable
# 安装官方最新LTS版本
sudo n lts

# 檢視更新結果
node -v
nodejs -v
```

參考連結：\
<https://segmentfault.com/a/1190000007542620>

## package.json

```
# 建立json
sudo npm init

# 後續設定可都先以enter帶過
```

參考連結：\
<http://souffle77-blog.logdown.com/posts/1316300-nodejs-package-json>
