VS code nodejs 調用js文件


1.  新建文件 server.js

var http = require('http');

http.createServer(function (request, response) {

    // 發送 HTTP 頭部 
    // HTTP 狀態值: 200 : OK
    // 內容類型: text/plain
    response.writeHead(200, {'Content-Type': 'text/plain'});

    // 發送響應數據 "Hello World"
    response.end('Hello World\n');
}).listen(8888);

// 終端打印如下信息
console.log('Server running at http://127.0.0.1:8888/');

2. 在Terminal中輸入 node server 或 node server.js

 輸出:   Server running at http://127.0.0.1:8888/

3. 在瀏覽器中輸入  http://127.0.0.1:8888/

瀏覽器顯示:Hello World

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM