node.js tutorial at hiroshima
TRANSCRIPT
-
Node.js
iwanaga
78 Web Touch Meeting in HIROSHIMA
-
1. Node.js
2. I/O
3. Node.js
Node.js
Node.js
-
()
Arduino Web IoT
www.atmarkit.co.jp/ait/kw/arduino_js.html
@y_iwanaga_
-
Node.js
(= )
-
HTTP, DNS
DB
I/O
-
I/O
https://software.intel.com/sites/products/collateral/hpc/vtune/performance_analysis_guide.pdf
http://mechanical-sympathy.blogspot.jp/2013/02/cpu-cache-flushing-fallacy.html
I/O CPU
L3 Cache 38 12 ns
RAM 250 65 ns
Disk 41,000,000 10,000,000 ns
Network 240,000,000 60,000,000 ns
I/O
-
I/O
I/O
multi thread
select I/O
-
I/O
Single thread I/O
I/O
-
Node.js Design Goals
1. Event Driven Async I/O
2. I/O Stream API
I/O event
3. API click
-
V8 Engine
http://docs.libuv.org/en/v1.x/design.html
-
Node.js I/O
-
https://github.com/ iwanaga/nodejs-hands-on
-
2. I/O3.
1. fs
-
event loop
-
event loop
-
event loop
-
event loop
-
Node.js Event Loop
-
EventEmitter
fs.readStream, net, http.Server
EventEmitter
1. on
2. emit
-
EventEmitter
-
EventEmitter
-
EventEmitter
-
EventEmitter
-
Node.js npm
-
npm
XML
MySQL
Web Framework
Node.js
etc
-
npm
package.json
-
https://nodejs.org/api/
-
1. Node.js2. http 3. npm
-
1. Node.js2. http 3. npm
-
nvm
-
nvm
1. nvm github
2. Install script curl https://raw.githubusercontent.com/creationix/nvm/v0.25.0/install.sh | bashsource ~/.nvm/nvm.sh
nvm install 0.12.2nvm alias default 0.12.2node -v
3. Usage
-
1. Node.js2. http 3. npm
-
https://nodejs.org/api/
HTTP
-
http.Server
-
http.Server
-
http.Server
-
curl http://localhost:3000/index.html
curl http://localhost:3000/ -d '{a: 1}'
-
1. Node.js2. http 3. npm
-
npm init
name node-hands-on
version 0.0.1
description hands-on codes
entry point index.js
test command
(npm test )
grunt test
author iwanaga
package.json
-
package.json
-
npm install lodash --save
1. lodash 2. node_modules 3. package.json
-
package.json
-
node_modules
npm install
C++
-
Node.js
-
Node.js Web
generator-angular-fullstack
-
angular-fullstack
YEOMAN
MongoDBExpressAngularJSNode.js
SocketIO
-
npm install g yonpm install g bowernpm install g grunt-clinpm install g generator-angular-fullstackyo angular-fullstack HandsOnApp
-
? What would you like to write scripts with? JavaScript? What would you like to write markup with? HTML? What would you like to write stylesheets with? CSS
-
? What Angular router would you like to use? uiRouter? Would you like to include Bootstrap?n? Would you scaffold out an authentication boilerplate?n
-
? Would you like to use mongoDB with Mongoose for data modeling?y? Would you like to use socket.io?Y
-
grunt serve:dist
JavaScriptCSS minify
script link
AngularJS CDN
dist
dist
node server/app.js
-
server
client
dist
e2e
Node.js
HTML, JavaScript, CSS
End To End
build:dist or serve:dist production
-
server
app.js
routes.js
HTTP
YEOMAN
Express API
-
server
api
API
resourceName
index.js
resourceName.controller.js
resourceName.model.js
resourceName.socket.js
resourceName.spec.js
-
server
yo angular-fullstack:endpoint resourceName
Model
( Controller, Socket )
(spec grunt test:server )
-
client
bower_components
index.html
grunt:build bower install
script, CSS
bower
-
client
app
AngularJS
uiName uiName.js uiName.controller.js
uiName.controller.spec.js
uiName.html
uiName.css
compenents
-
client
yo angular-fullstack:route uiName
Controller, HTML
( uiName.js )
(spec grunt test:client )
-
bower install angular-material
https://material.angularjs.org/
-
TODO
-
server
-
yo angular-fullstack todoyo angular-fullstack:endpoint todo
-
server
server/api/todo/todo.model.js
-
client
-
yo angular-fullstack:route todoyo angular-fullstack:service todoServicebower install angular-material --save
-
client client/app/todo/todo.html
-
client
client/app/todoService/todoService.js
-
client client/app/todo/todo.controller.js
-
client client/app/todo/todo.js
-
dev SocketIO serve
server/app.js
-
angular-material client/app/app.js
-
grunt serve
WebSocket
DB
-
Node.js