Node.js入門:Hello World


  馬上開始我們第一個Node.js應用:“Hello World”。打開你的編輯器,創建一個hello.js文件。編寫代碼保存該文件,並通過Node.js來執行。
  • 控制台輸出
1 console.log('hello, nodejs.') ; 

  • Web輸出
1 var http = require("http"); 
2 http.createServer(function(request, response) { 
3     response.writeHead(200, {"Content-Type": "text/html"}); 
4     response.write("Hello World!"); 
5     response.end(); 
6 }).listen(8000); 
  打開瀏覽器地址欄輸入http://localhost:8000/,可以在網頁上看到輸出結果。


免責聲明!

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



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