--- title: Node.js 學習筆記系列 - 01 安裝(On Win7) tags: JS/Node.js --- # Node.js 學習筆記系列 - 01 安裝(On Win7) By 蓉爸 RungBa Created: 2019-08-18 Revised: 2023-09-01 --- ## 一. 環境版本說明 #### 1. OS: MS-Win 7 #### 2. Node.js: v.10.16.3 <br> --- ## 二. Node.js 安裝 ### 方法一:Installer 安裝(略) ### 方法二:zip 安裝 1. 下載 node.js LTS binary for Windows,並解壓縮到自訂的資料夾,例如:D:\MyProject\JavaScript\Node.js\NodeJsSrc 。 2. 將上述資料夾,加到環境變數 PATH (系統的或是使用者的皆可),然後按快捷鍵 winkey+R 並輸入: rundll32 sysdm.cpl,EditEnvironmentVariables 3. 開啟一個 cmd 視窗(winkey+R and type cmd) 4. 輸入 node -v 與 npm -v 來驗證安裝結果 ![](https://i.imgur.com/2BPPW2M.png) ![](https://i.imgur.com/o6fF9Xa.png) <br> --- ## 三. 先在 cmd 寫第一支 node 測試程式 編輯一個 hello_node.js 檔,並輸入如下內容: ```javascript= console.log('Hello Node.js!'); ``` 存檔後(檔案位置 D:\MyProject\JavaScript\Node.js),開個 cmd,然後執行: ``` D:\MyProject\JavaScript\Node.js>node hello_node.js ``` ![](https://i.imgur.com/zRWBOQm.png) <br> --- ## 四. 寫 Web 第一支 node 測試程式 編輯一個 hello_world.js 檔,並輸入如下內容: ```javascript= var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World!'); }).listen(8080); ``` 利用 node 初始化 hello_world.js,如下: ``` D:\MyProject\JavaScript\Node.js>node hello_world.js ``` 開啟瀏覽器,並輸入 http://localhost:8080,第一次會看到訪火牆警告訊息,都勾選允許後,按下「允許存取」鈕,如下圖: ![](https://i.imgur.com/sDuVLdf.png) 如無意外,即可看到如下圖: ![](https://i.imgur.com/ObeQcmh.png) Ref: 1. [How to install NodeJS LTS on Windows as a local user (without admin rights)](https://stackoverflow.com/a/44951189) 2. [How To Install Node JS In Windows](https://www.dev2qa.com/how-to-install-node-js-in-windows/) 3. [Node.js Tutorial @W3Schools](https://www.w3schools.com/nodejs/) 4. [Persisting a Node API with PostgreSQL, without the help of ORM's like sequelize.](https://dev.to/ogwurujohnson/-persisting-a-node-api-with-postgresql-without-the-help-of-orms-like-sequelize-5dc5)5.