六角體驗營 # Todolist RESTful API : 開發新刪修查的API (實作6) - 環境設置(Git / heroku) > [**Todolist RESTful API : 開發新刪修查的API (實作5) - CRUD ( PATCH API )**](https://hackmd.io/JFbnJydEQuWnoUyegg1FTA?view) ## 13. Git 環境建置 > [**Git、GitHub 常用命令字元**](https://hackmd.io/_UYba6vtSYupdeQl8fG12A?view) * #### 13-1. 建立 git 環境 : 建立repository (資料夾中產生.git隱藏檔案) ```terminal= git init ``` * #### 13-2. .gitignore 忽略版控的項目 * 設置在專案資料夾中  * 不要版控的項目包含: **node_modules** (避免 npm 上傳檔案太大) **heroku會依據package.json中dependencies的npm安裝** .gitignore (如下) ```js= node_modules/ ``` * git status 查看版控項目 (不應有node_modules資料夾) ```terminal= git status ```  * #### 13-3. git add. / git commit -m "commit說明" * 新增檔案到索引區(staging area) ```terminal= git add . ``` * 將資料commit到本地數據庫(repository) ```terminal= git commit "設定環境" ``` * #### 13-4. git log 查看說明 ``` git log ```  <br><br> ## 14. heroku 環境設置 2022年官方已取消免費政策 > [**heroku 官網**](https://www.heroku.com/) > [**heroku CLI 下載**](https://devcenter.heroku.com/articles/heroku-cli) * #### **STEP 14-1.修改server.js** * process.env.PORT -> heroku 環境變數 ```js= server.listen( process.env.PORT || 3005); ``` * #### **STEP 14-2. 修改package.json設定** > * 確定有 **"start": "node server.js"** > -> npm start會自動執行 node server.js > * 設定 node 版本 ```json= { "name": "node.js-todolist-restful-api", "version": "1.0.0", "description": "", "main": "server.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "node server.js" 1.確定有 npm start 設定 }, "author": "", "license": "ISC", "dependencies": { "uuid": "^9.0.1" }, "engines": { 2.新增引擎 for node的版本設定 "node": "18.x" } } ``` * #### **STEP 14-3. 修改完server.js、package.json後git commit -m "說明文字"** ```terminal= git add . git commit -m "增加環境設定" ```  <br><br> ## 15. heroku 部屬流程 > 需先安裝 **heroku cli** * #### **STEP 15-1. 安裝heroku cli** * 安裝結束後重新開啟 vscode * terminal 查找 heroku 版本,回傳版本號代表安裝成功 ```terminal= heroku --version ```  * #### **STEP 15-2. heroku 登入** * terminal > heroku login 指令 ```terminal= heroku login ```  * 任意鍵進入登入頁面,登入成功會顯示email  * #### **STEP 15-3. heroku create 新增雲端主機** ## 16. heroku 測試 POSTMAN API * #### **STEP 16-1.**
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up