NodeJs學習(一)

來源:互聯網
上載者:User

標籤:style   blog   http   java   color   檔案   

第一步,大家都知道的,肯定下載安裝包,:http://nodejs.org/

下載完成後直接安裝,安裝成功後,開啟cmd,輸入:node -v

這時候,表示我們已經安裝成功了。

 

第二步,理所當然的,"hello world" 程式

建立一個hello.js檔案,裡邊輸入:console.log("hello world !");

cmd切換到這個js的目錄,輸入"node hello.js",輸入"hello world !",就成功了。

 

第三步,在瀏覽器中顯示“hello world !”

建立一個"http.js",代碼如下:

var http = require("http");http.createServer(function(request, response) {console.log(‘Server Running‘);response.writeHead(200, {"Content-Type": "text/plain"});response.write("Hello World");response.end();}).listen(8080);console.log(‘Server running at http://127.0.0.1:8080/‘);

cmd中輸入:"node http.js"

然後在瀏覽器中輸入:http://127.0.0.1:8080/ 就可以看到"hello world !"了

 取消偵聽:Ctrl+C  註:我把檔案尾碼改成.txt,一樣可以運行成功

 

第一次學習就到這裡(也是第一次寫),因為同類的文章有很多,如發現雷同,敬請諒解,這是我個人的學習過程,肯定是參考了你們的資料。

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.