Node.js 示例

2022-02-26 10:28 更新

第一個(gè)服務(wù)器的例子就從 “Hello World” 開(kāi)始:

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/');

把代碼拷貝到example.js文件里,使用node程序執(zhí)行:

> node example.js
Server running at http://127.0.0.1:8124/

在該Node.js官方文檔中的所有的例子都可以使用上述方法執(zhí)行。


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)