溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Node.js如何實現hello world

發布時間:2021-11-22 09:22:48 來源:億速云 閱讀:160 作者:小新 欄目:web開發

這篇文章主要為大家展示了“Node.js如何實現hello world”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“Node.js如何實現hello world”這篇文章吧。

首先下載node.js,然后解壓到E盤,改名為node,然后開始菜單輸入cmd,用cd命令切換到nodejs的解壓目錄:

Node.js如何實現hello world

***個例子:hello world。

在node目錄下建立hello.js文件,然后在里面輸入:

var sys = require("sys");  sys.puts("Hello world");

然后我們在命名臺中輸入命令node hello.js,就能看到命名臺輸出結果Hello world。

第二個例子:hello world2。

好了,這次我們試從游覽器中輸出hello world。在node目錄下建立http.js,然后輸入:

var sys = require("sys"),      http = require("http");  http.createServer(function(request, response) {      response.sendHeader(200, {"Content-Type": "text/html"});      response.write("Hello World!");      response.close();  }).listen(8080);  sys.puts("Server running at http://localhost:8080/");

然后我們在命名臺中輸入命令node http.js,在瀏覽器輸入http://localhost:8080/

Node.js如何實現hello world
Node.js如何實現hello world

第三個例子:hello world2。

node.js提供一個Buffer類用于轉換不同編碼的字符串。目前支持三種類型:'ascii','utf8'與'binary'。詳見這里

var Buffer = require('buffer').Buffer,  buf = new Buffer(256),  len = buf.write('\u00bd + \u00bc = \u00be', 0);  console.log(len + " bytes: " + buf.toString('utf8', 0, len));

第四個例子:hello world3。

//synopsis.js  //synopsis 摘要, 梗概,大綱  var http = require('http');     http.createServer(function (request, response) {    response.writeHead(200, {'Content-Type': 'text/plain'});    response.end('Hello World\n');  }).listen(8124);     console.log('Server running at http://127.0.0.1:8124/');

以上是“Node.js如何實現hello world”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女