`
Poechant
  • 浏览: 231362 次
博客专栏
Bebe66e7-3a30-3fc9-aeea-cfa3b474b591
Nginx高性能Web服务...
浏览量:24394
5738817b-23a1-3a32-86de-632d7da73b1e
Cumulus实时媒体服务...
浏览量:22156
社区版块
存档分类
最新评论

Introduction to Node.js(1)

 
阅读更多

Introduction to Node.js(1)

1 Hello World

$ sudo port install nodejs
$ echo "console.log(\"Hello World\");" > helloword.js
$ node helloworld.js

2 A simple TCP server

Create a file named “simple_tcp_server.js”

require("net").createServer(function(socket) {
    socket.write('Echo server\r\n');
    socket.pipe(socket);
}).listen(8765, "127.0.0.1");

Run your server:

$ node simple_tcp_server.js

3 A simple HTTP server

Create a file named “simple_http_server.js”

require("http").createServer(function(request, response) {
    console.log("Hello World");
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.write("Hello World\n");
    response.end();
}).listen(8765, "127.0.0.1");

-

转载请注明来自柳大的CSDN博客:blog.csdn.net/poechant

-

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics