xia的小窩

一起來coding和碼字吧

0%

從頭開始javascript的學習紀錄-安裝

安裝 npm ,如果不出意外就一直next即可

https://nodejs.org/zh-tw/download/

打開vscode,輸入

1
2
3
4
5
6
7
8
9
10
11
const http = require("http");
const hostname = "0.0.0.0";
const port = 6001;
const server = http.createServer((req, res) =>{
res.statusCode = 200;
res.setHeader("Content-type", "text/plain");
res.end("Hello world");
});
server.listen(port, hostname, () => {
console.log('Server running at http://${hostname}:${port}/');
});

在底下執行

1
node index.js

在瀏覽器輸入

1
http:127.0.0.1:6001

顯示結果如圖