第一个例子:hello world。
复制代码 代码如下:
var sys = require("sys");
sys.puts("Hello world");
第二个例子:hello world2。
复制代码 代码如下:
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/");
复制代码 代码如下:
var Buffer = require('buffer').Buffer,
buf DMqAzaNEY编程客栈= 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(f编程客栈unction (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8124);
console.log('Server running at http://127.DMqAzaNEY0.0.1:8124/');
编程客栈
第五个例子:编译C文件
复制代码 代码如下:
#include #include int main(){ printf("Hello World!!!"); exit(0); }
本文标题: 服务器端的JavaScript脚本 Node.js 使用入门
本文地址: http://www.cppcns.com/wangluo/javascript/130202.html
© 著作权归作者所有
举报
发表评论
0/200