SlideShare une entreprise Scribd logo
1  sur  21
Télécharger pour lire hors ligne
Node.js 介紹
Fin
Node.js 是什麼
• Javascript 運⾏行平台
• 讓Javascript跳脫瀏覽器的限制
• 輕易建⽴立Web Server
• 事件驅動 (Event driven)
• ⾮非阻塞式 (Nonblocking)
Why Node.js?
• 前後端語⾔言統⼀一,且能共⽤用模組
• 其特性⾮非常適合即時網路服務
• 本⾝身就可以是⼀一個HTTP伺服器
• 強⼤大的套件管理及開源社群
Why not Node.js?
• ⾮非常新的技術,版本甚⾄至還沒1.0
• 對需要⼤大量CPU的⼯工作不拿⼿手 - 直譯式
語⾔言
• library不如其他語⾔言來的多樣及完整
(但在快速發展中)
Node.js Dev Env Setup
• Install NVM
• Using NVM
Install NVM
• Install NVM
https://github.com/creationix/nvm/
• .bash_profile	
  加⼊入
curl	
  https://raw.github.com/creationix/nvm/master/install.sh	
  |	
  sh
[[	
  -­‐s	
  /Users/$USERNAME/.nvm/nvm.sh	
  ]]	
  &&	
  .	
  /Users/$USERNAME/.nvm/
nvm.sh	
  #	
  This	
  loads	
  NVM
Using NVM
#列出可安裝的node.js版本
nvm	
  ls-­‐remote
#安裝某版本的nvm
nvm	
  install	
  0.11
#列出本機端安裝的版本
nvm	
  ls
#使⽤用某版本
nvm	
  use	
  0.8
#設定預設版本
nvm	
  alias	
  default	
  0.8
Hello World!
• helloworld.js
• Run:
$	
  node	
  helloworld.js
Hello	
  World!
console.log(“Hello	
  World!”);
Directory Structure
project	
  root/
	
  	
  config/
	
  	
  controllers/
	
  	
  doc/
	
  	
  models/
	
  	
  public/
	
  	
  	
  	
  js/
	
  	
  	
  	
  css/
	
  	
  	
  	
  img/
	
  	
  test/
	
  	
  views/
	
  	
  package.json
	
  	
  README.md
Build a HTTP Server
#helloserver.js
#A	
  http	
  server	
  that	
  returns	
  ‘Hello	
  World’
var	
  http	
  =	
  require('http');	
  
http.createServer(function	
  (req,	
  res)	
  {
	
  	
  	
  	
  res.writeHead(200,	
  {'Content-­‐Type':	
  'text/plain'});
	
  	
  	
  	
  res.end('Hello	
  Worldn');
}).listen(8124,	
  "127.0.0.1");
console.log('Server	
  running	
  at	
  http://127.0.0.1:8124/');
$	
  node	
  helloserver.js
Server	
  running	
  at	
  http://127.0.0.1:8124/
Build a HTTP Server -
Using Express
$	
  npm	
  install	
  express
express@3.2.3	
  node_modules/express
├──	
  methods@0.0.1
├──	
  fresh@0.1.0
├──	
  range-­‐parser@0.0.4
├──	
  cookie-­‐signature@1.0.1
├──	
  qs@0.6.4
├──	
  buffer-­‐crc32@0.2.1
├──	
  cookie@0.0.5
├──	
  debug@0.7.2
├──	
  commander@0.6.1
├──	
  mkdirp@0.3.4
├──	
  send@0.1.0	
  (mime@1.2.6)
└──	
  connect@2.7.9	
  (pause@0.0.1,	
  bytes@0.2.0,	
  formidable@1.0.13)
Simplest Express Server
var	
  express	
  =	
  require('express');
var	
  app	
  =	
  express.createServer();
app.get('/',	
  function(req,	
  res)	
  {	
  
	
  	
  	
  	
  res.send('This	
  is	
  an	
  Express	
  Server');
});
app.listen(8000);
Message Board
/**
	
  *	
  Module	
  dependencies.
	
  */
var	
  express	
  =	
  require('express');
var	
  app	
  =	
  express();
//	
  Configuration
app.configure(function(){
	
  	
  app.set('views',	
  __dirname	
  +	
  '/views');
	
  	
  app.set('view	
  engine',	
  'jade');
	
  	
  app.use('/public',	
  express.static(__dirname	
  +	
  '/public'));
});
https://github.com/finfin/MessageBoard
//	
  Routes
app.get('/',	
  function(req,	
  res)	
  {
	
  	
  var	
  title	
  =	
  'Switter',
	
  	
  	
  	
  	
  	
  header	
  =	
  'Welcome	
  to	
  Switter';
	
  	
  res.render('index',	
  {
	
  	
  	
  	
  'title':	
  title,
	
  	
  	
  	
  'header':	
  header,
	
  	
  	
  	
  'tweets':	
  tweets,
	
  	
  })
})
var	
  tweets	
  =	
  [];
app.get('/tweets',	
  function(req,res)	
  {
	
  	
  res.send(tweets);
})
app.post('/send',	
  express.bodyParser(),	
  function(req,	
  res)	
  {
	
  	
  if	
  (req.body	
  &&	
  req.body.tweet)	
  {
	
  	
  	
  	
  tweets.push(req.body.tweet);
	
  	
  	
  	
  res.send({status:"ok",	
  message:"Tweet	
  received"});
	
  	
  }	
  else	
  {
	
  	
  	
  	
  //no	
  tweet?
	
  	
  	
  	
  res.send({status:"nok",	
  message:"No	
  tweet	
  received"});
	
  	
  }
})
app.listen(8000);
HTML Template - Jade
• 網⾴頁的呈現
• 語法簡潔
• http://jade-lang.com/
$	
  npm	
  install	
  jade
Jade Template
doctype	
  5
html(lang="zh-­‐tw")
	
   head
	
   	
   meta(charset="utf8")
	
   	
   link(rel='stylesheet',	
  href='/public/style.css')
	
   	
   title=	
  title
	
   body
	
   	
   h1=	
  header
	
   	
   block	
  content
extends	
  layout
block	
  content
	
   form(action="/send",	
  method="POST")
	
   	
   input(type="text",	
  length="140",	
  name="tweet")
	
   	
   input(type="submit",	
  value="發送")
	
   each	
  tweet	
  in	
  tweets
	
   	
   p=	
  tweet
• 套件越⽤用越多,要如何管理?
>>> NPM!
• package.json
Package Management
{
	
  	
  "name":	
  "MessageBoard",
	
  	
  "version":	
  "0.0.1",
	
  	
  "dependencies":	
  {
	
  	
  	
  	
  "express":	
  "*",
	
  	
  	
  	
  "jade":	
  "*"
	
  	
  }
}
#幫你安裝package.json裡⾯面所有的套件
$	
  npm	
  install
Improvement
function	
  acceptsHtml(header)	
  {
	
  	
  	
  	
  var	
  accepts	
  =	
  header.split(',');
	
  	
  	
  	
  for(i=0;	
  i	
  <	
  accepts.length;	
  i++)	
  {
	
  	
  	
  	
  	
  	
  	
  	
  if	
  (accepts[i]	
  ===	
  'text/html')	
  {	
  return	
  true;	
  };	
  
	
  	
  	
  	
  }
	
  	
  	
  	
  return	
  false;	
  
}
app.post('/send',	
  express.bodyParser(),	
  function(req,	
  res)	
  {
	
  	
  	
  	
  if	
  (req.body	
  &&	
  req.body.tweet)	
  {
	
  	
  	
  	
  	
  	
  	
  	
  tweets.push(req.body.tweet);
	
  	
  	
  	
  	
  	
  	
  	
  if(acceptsHtml(req.headers['accept']))	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  res.redirect('/',	
  302)
	
  	
  	
  	
  	
  	
  	
  	
  }	
  else	
  {
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  res.send({status:"ok",	
  message:"Tweet	
  received"});
	
  	
  	
  	
  	
  	
  	
  	
  };
	
  	
  	
  	
  }	
  else	
  {
	
  	
  	
  	
  	
  	
  	
  	
  //no	
  tweet?
	
  	
  	
  	
  	
  	
  	
  	
  res.send({status:"nok",	
  message:"No	
  tweet	
  received"});
	
  	
  	
  	
  };
});
Result
Resources
• http://nodejs.tw/
• http://www.nodebeginner.org/index-zh-
tw.html#javascript-and-nodejs
• https://www.facebook.com/groups/
node.js.tw
• http://book.nodejs.tw/index.html
About US
• http://www.zencher.com/
• 課程:雲端服務開發
http://www.zencher.com/#course/course-
cloudapp
• https://www.facebook.com/
thingsaboutwebdev

Contenu connexe

Tendances

How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0Takuya Tejima
 
Future Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETFuture Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETGianluca Carucci
 
Microservice Teststrategie mit Symfony2
Microservice Teststrategie mit Symfony2Microservice Teststrategie mit Symfony2
Microservice Teststrategie mit Symfony2Per Bernhardt
 
Using VueJS in front of Drupal 8
Using VueJS in front of Drupal 8Using VueJS in front of Drupal 8
Using VueJS in front of Drupal 8Brian Ward
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to AnsibleCédric Delgehier
 
Automating OSD and Post-OSD Configuration with Powershell and Orchestrator
Automating OSD and Post-OSD Configuration with Powershell and OrchestratorAutomating OSD and Post-OSD Configuration with Powershell and Orchestrator
Automating OSD and Post-OSD Configuration with Powershell and OrchestratorDigicomp Academy AG
 
What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012D
 
Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with AnsibleAhmed AbouZaid
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDDSudar Muthu
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationKumar Y
 
Application Layer in PHP
Application Layer in PHPApplication Layer in PHP
Application Layer in PHPPer Bernhardt
 
[Spring Camp 2013] Java Configuration 없인 못살아!
[Spring Camp 2013] Java Configuration 없인 못살아![Spring Camp 2013] Java Configuration 없인 못살아!
[Spring Camp 2013] Java Configuration 없인 못살아!Arawn Park
 
SockJS Intro
SockJS IntroSockJS Intro
SockJS IntroNgoc Dao
 
Network Automation: Ansible 102
Network Automation: Ansible 102Network Automation: Ansible 102
Network Automation: Ansible 102APNIC
 
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled InfrastructureCloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled InfrastructureHabeeb Rahman
 
Angular 1 + es6
Angular 1 + es6Angular 1 + es6
Angular 1 + es6장현 한
 
A Introduction of Packer
A Introduction of PackerA Introduction of Packer
A Introduction of PackerFreyr Lin
 

Tendances (20)

What is nodejs
What is nodejsWhat is nodejs
What is nodejs
 
How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0
 
Write php deploy everywhere
Write php deploy everywhereWrite php deploy everywhere
Write php deploy everywhere
 
Future Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETFuture Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NET
 
Microservice Teststrategie mit Symfony2
Microservice Teststrategie mit Symfony2Microservice Teststrategie mit Symfony2
Microservice Teststrategie mit Symfony2
 
Using VueJS in front of Drupal 8
Using VueJS in front of Drupal 8Using VueJS in front of Drupal 8
Using VueJS in front of Drupal 8
 
#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible#OktoCampus - Workshop : An introduction to Ansible
#OktoCampus - Workshop : An introduction to Ansible
 
Automating OSD and Post-OSD Configuration with Powershell and Orchestrator
Automating OSD and Post-OSD Configuration with Powershell and OrchestratorAutomating OSD and Post-OSD Configuration with Powershell and Orchestrator
Automating OSD and Post-OSD Configuration with Powershell and Orchestrator
 
What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012
 
Getting Started with Ansible
Getting Started with AnsibleGetting Started with Ansible
Getting Started with Ansible
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Application Layer in PHP
Application Layer in PHPApplication Layer in PHP
Application Layer in PHP
 
[Spring Camp 2013] Java Configuration 없인 못살아!
[Spring Camp 2013] Java Configuration 없인 못살아![Spring Camp 2013] Java Configuration 없인 못살아!
[Spring Camp 2013] Java Configuration 없인 못살아!
 
Celery
CeleryCelery
Celery
 
SockJS Intro
SockJS IntroSockJS Intro
SockJS Intro
 
Network Automation: Ansible 102
Network Automation: Ansible 102Network Automation: Ansible 102
Network Automation: Ansible 102
 
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled InfrastructureCloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
 
Angular 1 + es6
Angular 1 + es6Angular 1 + es6
Angular 1 + es6
 
A Introduction of Packer
A Introduction of PackerA Introduction of Packer
A Introduction of Packer
 

En vedette

Recent Developments in Donard
Recent Developments in DonardRecent Developments in Donard
Recent Developments in DonardPMC-Sierra Inc.
 
[INSIGHT OUT 2011] A23 database io performance measuring planning(alex)
[INSIGHT OUT 2011] A23 database io performance measuring planning(alex)[INSIGHT OUT 2011] A23 database io performance measuring planning(alex)
[INSIGHT OUT 2011] A23 database io performance measuring planning(alex)Insight Technology, Inc.
 
Web technologies for desktop development
Web technologies for desktop developmentWeb technologies for desktop development
Web technologies for desktop developmentDarko Kukovec
 
As media evaluation
As media evaluationAs media evaluation
As media evaluationstefan-k
 
Alert centraladminguide
Alert centraladminguideAlert centraladminguide
Alert centraladminguideArturo Salgado
 
Digital Review. August 2016
Digital Review. August 2016Digital Review. August 2016
Digital Review. August 2016AMDG
 
Doe microgrid workshop aug 30 31 2011 presentations
Doe microgrid workshop aug 30 31 2011 presentationsDoe microgrid workshop aug 30 31 2011 presentations
Doe microgrid workshop aug 30 31 2011 presentationsUCSD-Strategic-Energy
 
July digital review ARTOX media
July digital review ARTOX mediaJuly digital review ARTOX media
July digital review ARTOX mediaAMDG
 
Digital Review, June, 2016
Digital Review, June, 2016Digital Review, June, 2016
Digital Review, June, 2016AMDG
 
Regional Annual Report South Asia 2011
Regional Annual Report South Asia 2011 Regional Annual Report South Asia 2011
Regional Annual Report South Asia 2011 TerredesHommesNL
 
賽門鐵克 Storage Foundation 6.0 簡報
賽門鐵克 Storage Foundation 6.0 簡報賽門鐵克 Storage Foundation 6.0 簡報
賽門鐵克 Storage Foundation 6.0 簡報Wales Chen
 
Maya global pd 1
Maya global pd 1Maya global pd 1
Maya global pd 1sushicho
 
ORNL econ analysis of repurposed EV batteries for Stationary Applications
ORNL econ analysis of repurposed EV batteries for Stationary ApplicationsORNL econ analysis of repurposed EV batteries for Stationary Applications
ORNL econ analysis of repurposed EV batteries for Stationary ApplicationsUCSD-Strategic-Energy
 
Node.js ― Hello, world! の1歩先へ。
Node.js ― Hello, world! の1歩先へ。Node.js ― Hello, world! の1歩先へ。
Node.js ― Hello, world! の1歩先へ。Tatsuya Tobioka
 

En vedette (20)

Recent Developments in Donard
Recent Developments in DonardRecent Developments in Donard
Recent Developments in Donard
 
[INSIGHT OUT 2011] A23 database io performance measuring planning(alex)
[INSIGHT OUT 2011] A23 database io performance measuring planning(alex)[INSIGHT OUT 2011] A23 database io performance measuring planning(alex)
[INSIGHT OUT 2011] A23 database io performance measuring planning(alex)
 
Java 8 briefing
Java 8 briefingJava 8 briefing
Java 8 briefing
 
Web technologies for desktop development
Web technologies for desktop developmentWeb technologies for desktop development
Web technologies for desktop development
 
Nodejs on 02/22/2012
Nodejs on 02/22/2012Nodejs on 02/22/2012
Nodejs on 02/22/2012
 
As media evaluation
As media evaluationAs media evaluation
As media evaluation
 
Alert centraladminguide
Alert centraladminguideAlert centraladminguide
Alert centraladminguide
 
Catalago
CatalagoCatalago
Catalago
 
US Visas and Violations
US Visas and ViolationsUS Visas and Violations
US Visas and Violations
 
Digital Review. August 2016
Digital Review. August 2016Digital Review. August 2016
Digital Review. August 2016
 
Doe microgrid workshop aug 30 31 2011 presentations
Doe microgrid workshop aug 30 31 2011 presentationsDoe microgrid workshop aug 30 31 2011 presentations
Doe microgrid workshop aug 30 31 2011 presentations
 
Terre des hommes
Terre des hommes Terre des hommes
Terre des hommes
 
July digital review ARTOX media
July digital review ARTOX mediaJuly digital review ARTOX media
July digital review ARTOX media
 
Digital Review, June, 2016
Digital Review, June, 2016Digital Review, June, 2016
Digital Review, June, 2016
 
Regional Annual Report South Asia 2011
Regional Annual Report South Asia 2011 Regional Annual Report South Asia 2011
Regional Annual Report South Asia 2011
 
賽門鐵克 Storage Foundation 6.0 簡報
賽門鐵克 Storage Foundation 6.0 簡報賽門鐵克 Storage Foundation 6.0 簡報
賽門鐵克 Storage Foundation 6.0 簡報
 
Maya global pd 1
Maya global pd 1Maya global pd 1
Maya global pd 1
 
ORNL econ analysis of repurposed EV batteries for Stationary Applications
ORNL econ analysis of repurposed EV batteries for Stationary ApplicationsORNL econ analysis of repurposed EV batteries for Stationary Applications
ORNL econ analysis of repurposed EV batteries for Stationary Applications
 
Madrid protocol
Madrid protocolMadrid protocol
Madrid protocol
 
Node.js ― Hello, world! の1歩先へ。
Node.js ― Hello, world! の1歩先へ。Node.js ― Hello, world! の1歩先へ。
Node.js ― Hello, world! の1歩先へ。
 

Similaire à Nodejs first class

Build Web Apps using Node.js
Build Web Apps using Node.jsBuild Web Apps using Node.js
Build Web Apps using Node.jsdavidchubbs
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.pptWalaSidhom1
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express Jeetendra singh
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js frameworkBen Lin
 
Build web application by express
Build web application by expressBuild web application by express
Build web application by expressShawn Meng
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST APICaldera Labs
 
Building your first Node app with Connect & Express
Building your first Node app with Connect & ExpressBuilding your first Node app with Connect & Express
Building your first Node app with Connect & ExpressChristian Joudrey
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Matthew Groves
 
Full Stack Development with Node.js and NoSQL
Full Stack Development with Node.js and NoSQLFull Stack Development with Node.js and NoSQL
Full Stack Development with Node.js and NoSQLAll Things Open
 
node.js practical guide to serverside javascript
node.js practical guide to serverside javascriptnode.js practical guide to serverside javascript
node.js practical guide to serverside javascriptEldar Djafarov
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)Igor Bronovskyy
 
Node js introduction
Node js introductionNode js introduction
Node js introductionAlex Su
 
Node.js in action
Node.js in actionNode.js in action
Node.js in actionSimon Su
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSCosmin Mereuta
 
Server Side Apocalypse, JS
Server Side Apocalypse, JSServer Side Apocalypse, JS
Server Side Apocalypse, JSMd. Sohel Rana
 
Node.js System: The Approach
Node.js System: The ApproachNode.js System: The Approach
Node.js System: The ApproachHaci Murat Yaman
 

Similaire à Nodejs first class (20)

Build Web Apps using Node.js
Build Web Apps using Node.jsBuild Web Apps using Node.js
Build Web Apps using Node.js
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 
Build web application by express
Build web application by expressBuild web application by express
Build web application by express
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
 
Building your first Node app with Connect & Express
Building your first Node app with Connect & ExpressBuilding your first Node app with Connect & Express
Building your first Node app with Connect & Express
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017
 
Full Stack Development with Node.js and NoSQL
Full Stack Development with Node.js and NoSQLFull Stack Development with Node.js and NoSQL
Full Stack Development with Node.js and NoSQL
 
node.js practical guide to serverside javascript
node.js practical guide to serverside javascriptnode.js practical guide to serverside javascript
node.js practical guide to serverside javascript
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 
5.node js
5.node js5.node js
5.node js
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Node.js in action
Node.js in actionNode.js in action
Node.js in action
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JS
 
Server Side Apocalypse, JS
Server Side Apocalypse, JSServer Side Apocalypse, JS
Server Side Apocalypse, JS
 
Node.js System: The Approach
Node.js System: The ApproachNode.js System: The Approach
Node.js System: The Approach
 
NodeJS
NodeJSNodeJS
NodeJS
 

Dernier

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Dernier (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

Nodejs first class

  • 2. Node.js 是什麼 • Javascript 運⾏行平台 • 讓Javascript跳脫瀏覽器的限制 • 輕易建⽴立Web Server • 事件驅動 (Event driven) • ⾮非阻塞式 (Nonblocking)
  • 3. Why Node.js? • 前後端語⾔言統⼀一,且能共⽤用模組 • 其特性⾮非常適合即時網路服務 • 本⾝身就可以是⼀一個HTTP伺服器 • 強⼤大的套件管理及開源社群
  • 4. Why not Node.js? • ⾮非常新的技術,版本甚⾄至還沒1.0 • 對需要⼤大量CPU的⼯工作不拿⼿手 - 直譯式 語⾔言 • library不如其他語⾔言來的多樣及完整 (但在快速發展中)
  • 5. Node.js Dev Env Setup • Install NVM • Using NVM
  • 6. Install NVM • Install NVM https://github.com/creationix/nvm/ • .bash_profile  加⼊入 curl  https://raw.github.com/creationix/nvm/master/install.sh  |  sh [[  -­‐s  /Users/$USERNAME/.nvm/nvm.sh  ]]  &&  .  /Users/$USERNAME/.nvm/ nvm.sh  #  This  loads  NVM
  • 7. Using NVM #列出可安裝的node.js版本 nvm  ls-­‐remote #安裝某版本的nvm nvm  install  0.11 #列出本機端安裝的版本 nvm  ls #使⽤用某版本 nvm  use  0.8 #設定預設版本 nvm  alias  default  0.8
  • 8. Hello World! • helloworld.js • Run: $  node  helloworld.js Hello  World! console.log(“Hello  World!”);
  • 9. Directory Structure project  root/    config/    controllers/    doc/    models/    public/        js/        css/        img/    test/    views/    package.json    README.md
  • 10. Build a HTTP Server #helloserver.js #A  http  server  that  returns  ‘Hello  World’ var  http  =  require('http');   http.createServer(function  (req,  res)  {        res.writeHead(200,  {'Content-­‐Type':  'text/plain'});        res.end('Hello  Worldn'); }).listen(8124,  "127.0.0.1"); console.log('Server  running  at  http://127.0.0.1:8124/'); $  node  helloserver.js Server  running  at  http://127.0.0.1:8124/
  • 11. Build a HTTP Server - Using Express $  npm  install  express express@3.2.3  node_modules/express ├──  methods@0.0.1 ├──  fresh@0.1.0 ├──  range-­‐parser@0.0.4 ├──  cookie-­‐signature@1.0.1 ├──  qs@0.6.4 ├──  buffer-­‐crc32@0.2.1 ├──  cookie@0.0.5 ├──  debug@0.7.2 ├──  commander@0.6.1 ├──  mkdirp@0.3.4 ├──  send@0.1.0  (mime@1.2.6) └──  connect@2.7.9  (pause@0.0.1,  bytes@0.2.0,  formidable@1.0.13)
  • 12. Simplest Express Server var  express  =  require('express'); var  app  =  express.createServer(); app.get('/',  function(req,  res)  {          res.send('This  is  an  Express  Server'); }); app.listen(8000);
  • 13. Message Board /**  *  Module  dependencies.  */ var  express  =  require('express'); var  app  =  express(); //  Configuration app.configure(function(){    app.set('views',  __dirname  +  '/views');    app.set('view  engine',  'jade');    app.use('/public',  express.static(__dirname  +  '/public')); }); https://github.com/finfin/MessageBoard
  • 14. //  Routes app.get('/',  function(req,  res)  {    var  title  =  'Switter',            header  =  'Welcome  to  Switter';    res.render('index',  {        'title':  title,        'header':  header,        'tweets':  tweets,    }) }) var  tweets  =  []; app.get('/tweets',  function(req,res)  {    res.send(tweets); }) app.post('/send',  express.bodyParser(),  function(req,  res)  {    if  (req.body  &&  req.body.tweet)  {        tweets.push(req.body.tweet);        res.send({status:"ok",  message:"Tweet  received"});    }  else  {        //no  tweet?        res.send({status:"nok",  message:"No  tweet  received"});    } }) app.listen(8000);
  • 15. HTML Template - Jade • 網⾴頁的呈現 • 語法簡潔 • http://jade-lang.com/ $  npm  install  jade
  • 16. Jade Template doctype  5 html(lang="zh-­‐tw")   head     meta(charset="utf8")     link(rel='stylesheet',  href='/public/style.css')     title=  title   body     h1=  header     block  content extends  layout block  content   form(action="/send",  method="POST")     input(type="text",  length="140",  name="tweet")     input(type="submit",  value="發送")   each  tweet  in  tweets     p=  tweet
  • 17. • 套件越⽤用越多,要如何管理? >>> NPM! • package.json Package Management {    "name":  "MessageBoard",    "version":  "0.0.1",    "dependencies":  {        "express":  "*",        "jade":  "*"    } } #幫你安裝package.json裡⾯面所有的套件 $  npm  install
  • 18. Improvement function  acceptsHtml(header)  {        var  accepts  =  header.split(',');        for(i=0;  i  <  accepts.length;  i++)  {                if  (accepts[i]  ===  'text/html')  {  return  true;  };          }        return  false;   } app.post('/send',  express.bodyParser(),  function(req,  res)  {        if  (req.body  &&  req.body.tweet)  {                tweets.push(req.body.tweet);                if(acceptsHtml(req.headers['accept']))  {                          res.redirect('/',  302)                }  else  {                        res.send({status:"ok",  message:"Tweet  received"});                };        }  else  {                //no  tweet?                res.send({status:"nok",  message:"No  tweet  received"});        }; });
  • 20. Resources • http://nodejs.tw/ • http://www.nodebeginner.org/index-zh- tw.html#javascript-and-nodejs • https://www.facebook.com/groups/ node.js.tw • http://book.nodejs.tw/index.html
  • 21. About US • http://www.zencher.com/ • 課程:雲端服務開發 http://www.zencher.com/#course/course- cloudapp • https://www.facebook.com/ thingsaboutwebdev