# How to use Node.js Node.js - https://nodejs.org/en express.js NPM套件 - https://www.npmjs.com/package/express Dockerode 使用 Node.js 控制 docker - https://www.npmjs.com/package/dockerode xtermjs 網頁上產生 Terminal 介面 - https://xtermjs.org/ ## 學習資源 Node.js 控制處理程序 stdin stdout https://blog.logrocket.com/using-stdout-stdin-stderr-node-js/ ### express.js express.js 安裝 https://expressjs.com/en/starter/installing.html express.js 路由 https://expressjs.com/en/guide/routing.html express.js 服務靜態網頁 https://expressjs.com/en/starter/static-files.html ### SocketIO SocketIO Websocket (長連結HTTP) https://socket.io/ express.js + SocketIO https://medium.com/kocfinanstech/socket-io-with-node-js-express-5cc75aa67cae ## 安裝 Node.js https://nodejs.org/en 選擇LTS版本安裝  ## 使用 Node.js 建立網頁伺服器 建立一個 Node.js 專案 ```bash mkdir myapp cd myapp npm init -y npm install express ``` 寫一個檔案 `src/index.js` ```javascript const express = require('express') const app = express() app.get('/', function (req, res) { res.send('Hello World') }) app.listen(3000) console.log('Server running at http://localhost:3000/') ``` 打開 `package.json` 找到 ```json "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, ``` 新增一個指令 ```json "scripts": { "start": "node src/index.js", "test": "echo \"Error: no test specified\" && exit 1" }, ``` 打指令 `npm start` 或 `npm run start` 即可啟動網頁伺服器 
×
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