现在的位置: 首页 > 综合 > 正文

Intro to Node.js

2018年09月30日 ⁄ 综合 ⁄ 共 885字 ⁄ 字号 评论关闭

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)

抱歉!评论已关闭.