分享 推播通知
目前身份: 訪客

node.js最強的就是它可以建構一個http服務器,也就是說我不用apache了,也不用nginx了

直接在js上,就可以弄一個web server來玩

 

代碼如下:


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 Node.js World.\n');

});

server.listen(port, hostname, () => {

    console.log(`Server running at http://${hostname}:${port}/`);

}); 

2
人氣 1995
學習 發表在 留言 (0) 人氣 (1995)
不設分類
分享給朋友
網址

想對外分享這則貼文嗎?運用網址更方便呦~

載入中...