熱搜:win11繞過硬件限制安裝 一鍵重裝Win10系統(tǒng) 最干凈的u盤啟動(dòng)盤 真正純凈版的win7系統(tǒng)
時(shí)間:2015-07-14 15:08:24 作者:zhijie 來源:系統(tǒng)之家 1. 掃描二維碼隨時(shí)看資訊 2. 請(qǐng)使用手機(jī)瀏覽器訪問: https://m.xitongzhijia.net/xtjc/20150714/52866.html 手機(jī)查看 評(píng)論 反饋
Node.js為Linux系統(tǒng)提供了豐富的各種模塊的JavaScript庫,從而簡(jiǎn)化了使用Node.js,一個(gè)很大的程度上方便web應(yīng)用程序的研究與開發(fā)。本文就來介紹一下Node.js一個(gè)最基礎(chǔ)的知識(shí),那就是在Ubuntu中運(yùn)行Hello world。
安裝好node.js后,在任意路徑新建文件helloworld.js,輸入如下內(nèi)容:
console.log(“Hello world!”)
然后在該路徑下啟動(dòng)Terminal(Windows中就是命令行Command Line),或者先啟動(dòng)Terminal再使用cd命令切換到該路徑也行(Windows同理),然后輸入命令
node helloworld.js
回車,窗口中會(huì)輸出“Hello world!”字樣。
以上就是node的最簡(jiǎn)單的一個(gè)hello world程序。node.js作為服務(wù)器編程技術(shù),另一個(gè)基本的hello world程序就是在網(wǎng)頁上輸出Hello world.
將helloworld.js的內(nèi)容改成如下內(nèi)容:
var http =require(“http”);//獲取http對(duì)象
//利用http對(duì)象的createServer函數(shù)創(chuàng)建一個(gè)server對(duì)象,參數(shù)是一個(gè)無參函數(shù),函數(shù)利用response對(duì)象向瀏覽器寫入頭信息和文本
var server = http.createServer(function(request, response) {
response.writeHead(200, {“Content-Type”:“text/plain”});
response.write(“Hello World”);
response.end();
});
//server對(duì)象監(jiān)聽8888端口
server.listen(8888);
然后再執(zhí)行node helloworld.js,然后在瀏覽器中訪問https://localhost:8888/
瀏覽器中就會(huì)顯示Hello world!
Ubuntu系統(tǒng)使用Node.js運(yùn)行Hello world的介紹了,只要學(xué)會(huì)這個(gè)技巧,就算是對(duì)Node.js開始入門了。
發(fā)表評(píng)論
共0條
評(píng)論就這些咯,讓大家也知道你的獨(dú)特見解
立即評(píng)論以上留言僅代表用戶個(gè)人觀點(diǎn),不代表系統(tǒng)之家立場(chǎng)