Node.js 的初体验
例子1:
1.首先第一步 :要 下载 node.js。 官网 上可以下载
下载完后,是这个玩意。

2. 打开 node.js ,然后输入
// 引入http模块
var http = require("http");
// 创建server,指定处理客户端请求的函数
http.createServer(
function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World!");
response.end();
}
).listen(8000);
console.log("Hello World is listening at port 8000");
显示结果为
![]()
3. 在浏览器 显示 :输入 localhost:8000,显示

例子2:
1. 打开node.js ,输入
var sys = require("util")var http = require("http");http.createServer(function(request, response) { // response.sendHeader(200, {"Content-Type": "text/html"}); response.writeHeader(200, {"Content-Type": "text/html"}); response.write("Hello World!"); // response.close(); response.end();}).listen(8080);sys.puts("Server running at http://localhost:8080/");
2.打开游览器 输入 : http://localhost:8080/
显示图为:
例子3
1.打开 node.js
输入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/');![]()
2.打开浏览器 ,输入http://localhost:8124/:
显示界面为
![]()




浙公网安备 33010602011771号