View
2.416
Download
12
Category
Tags:
Preview:
Citation preview
Node.js Getting StartBy @朴灵
12年7月19日星期四
http://www.alibabatech.org/gprofile/37
12年7月19日星期四
Install Node.js
• 下载安装(http://nodejs.org/#download)
• node -v
12年7月19日星期四
Hello world!
node
> console.log(‘hello world!’);
12年7月19日星期四
Hello world!
var http = require('http');http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n');}).listen(1337);
console.log('Server running at http://127.0.0.1:1337/');
12年7月19日星期四
NPM
• npm install connect
• npm install connect --registry=http://registry.npm.tbdata.org
• npm ls
• npm config ls
• npm publish .
12年7月19日星期四
Module// hello.jsexports.helloWorld = function () { console.log('Hello World!');};
// example.jsvar hello = require(‘./hello’);hello.helloWorld();
12年7月19日星期四
Package
• npm init
12年7月19日星期四
小结
• 安装• Hello world
• NPM & CommonJS Module/Package
12年7月19日星期四
Web Server
var connect = require('connect');
var app = connect();app.use(connect.static("./public")));app.use(connect.directory("./public"));app.listen(8001);console.log("Running at http://localhost:8001");
12年7月19日星期四
Connect中间件
// 使用中间件技术app.use(function (req, res, next) {
});
12年7月19日星期四
目录结构• /dispatch.js
• /app.js
• /routes.js
• /controllers/ 业务逻辑相关
• /views/
• /common/ 跟业务相关的公共模块
• /proxy/ 数据访问代理层
• /lib/ 跟业务无关的公共模块
• /assets/ 静态文件
• /test/ 测试
• /bin/ 可执行文件
• /tools/ 工具
• /node_moudules
12年7月19日星期四
Node-Clustervar cluster = require('node-cluster');var master = new cluster.Master();master.register(8080, 'app.js');master.dispatch(); var cluster = require('node-cluster');
var worker = new cluster.Worker();var connect = require('connect');var app = connect();app.use(connect.static("./public")));app.use(connect.directory("./public"));worker.ready(function (socket) { app.emit('connection', socket);});
12年7月19日星期四
本地NPM
12年7月19日星期四
本地NPM
官方NPM
12年7月19日星期四
本地NPM
官方NPM
12年7月19日星期四
本地NPM
官方NPM单向同步
12年7月19日星期四
本地NPM
本地NPM 官方NPM单向同步
12年7月19日星期四
本地NPM
本地NPM 官方NPM单向同步
12年7月19日星期四
本地NPM
本地NPM 官方NPM
项目
单向同步
12年7月19日星期四
本地NPM
本地NPM 官方NPM
项目
单向同步
12年7月19日星期四
本地NPM
本地NPM 官方NPM
项目
单向同步
私有模块
12年7月19日星期四
本地NPM
本地NPM 官方NPM
项目
单向同步
私有模块
12年7月19日星期四
本地NPM
本地NPM 官方NPM
项目
单向同步
私有模块
12年7月19日星期四
本地NPM
本地NPM 官方NPM
项目
单向同步
私有模块 公有模块
12年7月19日星期四
本地NPM
本地NPM 官方NPM
项目
单向同步
私有模块 公有模块
12年7月19日星期四
常用模块• connect/ejs
• mongoskin/redis/mredis
• eventproxy
• node-cluster
• iconv
• mocha/should/rewire
• node-dev
12年7月19日星期四
阿里专用模块• taobaosession
• taobao-cdn
• taobaostatus
• sm-client
• hsf
• itier
• kfc-client
12年7月19日星期四
References
• http://www.infoq.com/cn/master-nodejs
• http://www.windowsazure.com/en-us/develop/nodejs/tutorials/getting-started/
• http://nodeguide.com/beginner.html
• http://www.i-programmer.info/programming/javascript/3400-getting-started-with-nodejs.html
12年7月19日星期四
Recommended