node.js
=====================
*下載、安裝 Node.js
https://nodejs.org/en/
*選最新版安裝:
12.2.0 Current
Latest Features
=====================
*啟動與測試伺服器:
*建立專案資料夾node
建立空白檔案server.js
*在官網選about:
https://nodejs.org/en/
copy下列程式到server.js空白檔案:
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
//html
//res.setHeader('Content-Type', 'text/html');
//res.end('Hello <u>World vvvcc</u>\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
*在cmd切換資料夾到專案資料夾node
執行指令:
node server
出現:
Server running at http://127.0.0.1:3000/
*在瀏覽器輸入
http://127.0.0.1:3000/
出現:
Hello World
=====================
沒有留言:
張貼留言