Intro to Node.js

来源:互联网 发布:java 抽奖系统设计 编辑:程序博客网 时间:2024/05/15 03:19

Node.js http://node.codeschool.com/levels/1

What

Allows you to build scalable network applications using JavaScript on the server-side


Node.js is fast, because it is mostly C code.

Usage

• Websocket Server (聊天服务端)

• Fast File Upload Client

• Ad Server

• Any Real-Time Data Apps

Blocking vs NonBlocking

Blocking Code

var contents = fs.readFileSync('/etc/hosts');console.log(contents);console.log('Doing something else');
NonBlocking Code
fs.readFile('/etc/hosts',function(err,contents){console.log(contents);});console.log('Doing something else');
Hello World

var http = require('http');http.createServer(function(request, response) {response.writeHead(200);response.write("Hello, this is dog.");response.end();}).listen(8080);console.log('Listening on port 8080...');

Why JS

JavaScript has certain characteristics that make it very different than other dynamic languages, namely that it has no concept of threads. Its model of concurrency is completely based around events. (Ryan Dahl)
0 0
原创粉丝点击