教學影音:
https://youtu.be/SY5sRC2idk0
============
安裝 Node.js 步驟
1. http://nodejs.org/ 下載安裝
npm install connect
npm install express
npm install morgan
2. 開啟命令提示字元,輸入 node
3. hello.js
var http = require('http');
http.createServer(function(req, res){
res.writeHead(200, { 'Content-Type': 'text/html' });
res.write('
Hello Helen, this is Node.js
');
res.end('Hello world');}).listen(3232);
console.log("HTTP Server is listening at port 3232");
------------
//引用'http'模組
const http = require('http');
//設定server網址,因為在本機端測試,所以輸入127.0.0.1
const hostname = '127.0.0.1';
//設定port號,這邊多少都可以,不要和現有的port重複就好
const port = 3000;
//新增一個server並指定他的頁面資訊,內容為'Hello World!'
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World!\n');
});
//監聽剛剛新建的server,開啟後就執行裡面的console.log
server.listen(port, hostname, () => {
console.log("Server running at http://${hostname}:${port}/");
});
-------------
4. 命令提示字元,輸入 node my.js
5. 確認npm 命令提示字元看一下 npm (node -v和npm -v)
=====
安裝
https://docs.microsoft.com/zh-tw/windows/dev-environment/javascript/nodejs-on-windows
NodeJS Web
https://docs.microsoft.com/zh-tw/windows/dev-environment/javascript/nodejs-beginners-tutorial