Upload
peter-hecker
View
163
Download
0
Embed Size (px)
Citation preview
Node.js - Anwendungen mit Visual Studio
entwickeln
#dwx14
feed
back
@de
velo
per-w
eek.
de
Speaker: Peter Hecker
Peter Hecker
• Seit 1986: „Entwickler, Trainer“
• Seit 1995: „Web-Entwicklung“
• Seit 2002: „ASP.NET"
• Seit 2009: „Mobile WebApps“
• Vorstand in der GFU Cyrus AG
GFU Cyrus AG„Ihr Partner für IT-Schulungen“
s1694Schulung: „Node.js für NET-Entwicker“
#dwx2014-Teilnehmer bekommen 20% Rabatt!
Agenda• Einführung in Node.js
• Integration Node.js und .NET
• Web-Anwendungen mit Node.js
• Anwendungsfälle und Beispiele
• Fazit
#dw
x14
Einführung in Node.js
#dw
x14
Node.js• Node.js ist eine plattformübergreifende
Laufzeitumgebung für JavaScript-Anwendungen.
• Node.js ermöglicht die einfache Entwicklung von schnellen und skalierbaren JavaScript-Anwendungen.
• Node.js JavaScript-Anwendungen laufen typischerweise auf einem Server.
Der ErfinderRyan Dahl: „Node.js, Evented I/O for V8 Javascript“
JSConf.EU, Sunday November 8th, 2009
node.js in brief (2009)
• Server-Side JavaScript
• Built on Google’s V8
• Evented, Non-Blocking I/O
• CommonJS module system
• 8000 lines of C/C++, 2000 lines of JavaScript (14 Contributor)
http://www.youtube.com/watch?v=ztspvPYybIY
What ist V8?• V8 is Google's open source high-
performance JavaScript engine, written in C++ and used in Google Chrome, the open source browser from Google.
• It implements ECMAScript as specified in ECMA-262, 3rd edition, and runs on Windows XP and Vista, Mac OS X 10.5+, and Linux systems that use IA-32, ARM or MIPS processors.
• V8 can run standalone, or can be embedded into any C++ application.
https://developers.google.com/v8/
node standard library
node bindings (http, socket, file system)
V8 thread pool (libeio)
event loop (libev)
cypto (OpenSSL)
DNS (c-ares)
JavaScript
C/C++
Node.js - Architektur
• Single Threaded
• Asynchronous
• Event Loop
• Non blocking I/O
Ryan Dahl„I/O needs to be done differently“
Ryan Dahl„In many cases, just waiting for the response“
Klassische ServerMulti-Threaded - Blocking I/O
http://blog.cloudfoundry.com/2012/06/27/future-proofing-your-apps-cloud-foundry-and-node-js/
Ryan Dahl„This is the node.js project: To provide a purely evented, non-blocking infrastructure to script highly concurrent programs“
Node.jsSingle Threaded, Event Loop, Non-Blocking I/O
http://blog.cloudfoundry.com/2012/06/27/future-proofing-your-apps-cloud-foundry-and-node-js/
Single Threaded, Event Loop, Non-Blocking I/O
• Weniger Speicherverbrauch
• Weniger CPU-Overhead
• Bessere Skalierbarkeit
Fundamentals• Globals • STDIO • Timers • Modules • Events • Buffers • Streams • C/C++ Addons
Network I/O• HTTP • HTTPS • URL • Query Strings • Net • UDP/Datagram • DNS
File system I/O• File System • Path Process I/O / V8 VM• Process • VM • Child Processes • Cluster
Terminal/Console• REPL • Readline • TTY
Testing & debugging• Assertion Testing • Debugger • Utilities
Misc• Crypto • TLS/SSL • String Decoder • ZLIB • OS
http://nodejs.org/api/modules.html
Node.js Core Modules
npm - Der Node.js Paket Managerhttps://www.npmjs.org/
Node.js - Homepagehttp://nodejs.org/
JoyentDas Unternehmen hinter Node.js und npm.
http://www.joyent.com
Integration Node.js und .NET
#dw
x14
Node.js und .NET• Node.js für Windows
• http://nodejs.org/
• Node.js Tools for Visual Studio (NTVS)
• https://nodejstools.codeplex.com/
• Edge.js
• http://tjanczuk.github.io/edge/
„Hello World“ mit Node.js
VS.NET + NTVS• Verschiedene Projektvorlagen
• Integration der Node.js-Paketverwaltung (npm)
• JavaScript-Code-Vervollständigung (Intellisense)
• Node.js-Interactive Window
• Node.js-Debugger-Integration
• Windows Azure Veröffentlichung
Edge.js
• npm-Module und nuget-Pakete für die Integration von Node.js und .NET auf Prozessebene
• Für C#, F#, Python (mit IronPython) und Windows PowerShell
• Ganz aktuell auch für Mac OSX und Linux
http://tjanczuk.github.io/edge/
„Edge.js is 32x faster than a cross-process call“
https://github.com/tjanczuk/edge/wiki/Performance
npm install edge
Web-Anwendungen mit Node.js
#dw
x14
Web-Anwendungen mit Node.js
• Architekturvergleich .NET / Node.js
• Module, Pakete und Abhängigkeiten in Node.js
• Einfache Web-Server in Node.js
• Das Node.js MVC-Framework „Express“
.NET versus Node.jsSoftware-Architekturvergleich
IIS / ASP.NET / .NET Node.exe / Node Modules
C# / VB.NET / etc. JavaScript
EF/SQL Server NoSQL (MongoDB)
ASP.NET MVC / Razor Express + Jade/Razor
ASP.NET WebForms Express + EJS
ASP.NET WebAPI Express
SignalR WebSockets (Socket.IO)
http://mongodb.org/
http://expressjs.com/
http://socket.io/
Module, Pakete und Abhängigkeiten in
Node.js
CommonJShttp://www.commonjs.org/
Einfache Web-Server in Node.js
node web moduleshttp://nodewebmodules.com/
Express Frameworkhttp://expressjs.com/
Das Node.js MVC-Framework
„Express“
Installation
Die Node.js-View Engine „Jade“
npm install jade --savehttp://jade-lang.com/
Die Node.js-View Engine „EJS“
npm install ejs --savehttp://embeddedjs.com/
EJS-Hinweise• Standardmäßig keine Layout-Konzepte!!
• Zusätzliche npm-Projekte
• ejs-locals
• https://github.com/RandomEtc/ejs-locals
• express-ejs-layouts
• https://github.com/Soarez/express-ejs-layouts
• express-partials
• https://github.com/publicclass/express-partials
Die Node.js-View Engine „Vash“
npm install vash --savehttps://github.com/kirbysayshi/vash
Erstellen eines Node.js-Controllers
Erstellen eines Node.js-Datenservice
Statische Ressourcen in Node.js einbinden
Anwendungsfälle und Beispiele
#dw
x14
Node.js für Web-Entwickler
Grunthttp://gruntjs.com/
Bowerhttp://bower.io/
Yeomanhttp://yeoman.io/
Anwendungsfälle• The Internet of Things
• E-Commerce
• Payment Processing
• Social Media
• Realtime Services
• Media
• Enterprise Web Services
IBM und Node.js
• „When you add thousands of devices to a network it’s going to be impossible to program in the same way we program computers today. IBM is working on Node-RED a tool to help “wire” the internet of things.“
http://nodered.org/
LinkedIn und Node.js
• Anforderung: „Mobilen App-Infrastruktur“
• Weniger Code
• Weniger Ressourcen - von 30 auf 3 Server
• Schneller - teilweise bis 20x
• Stabiler
http://highscalability.com/blog/2012/10/4/linkedin-moved-from-rails-to-node-27-servers-cut-and-up-to-2.html
Groupon und Node.js• Anforderung:
„50.000 Requests / Minute“
• Node.js-Infrastruktur schafft diese Datenverkehr mit weniger Hardware
• Ladezeiten verbessern sich um 50%
• Globale Änderungen lassen sich schneller realisieren und verteilen
http://www.datacenterknowledge.com/archives/2013/12/06/need-speed-groupon-migrated-node-js/
Walmart und Node.js• Anforderung:
„Black Friday“
• 55% des Datenverkehrs wurde über Node.js-Server verarbeitet, ohne einen einzigen Serverausfall
• Die durchschnittliche CPU-Auslastung lag bei 1%
• Softwareverteilung bei 200.000.000 aktiven Nutzern
http://www.joyent.com/developers/videos/node-js-at-walmart-going-to-production-debugging-monitoring
Yahoo und Node.js
• Ca. 200 Entwickler programmieren für Node.js
• 500 interne Node-Module
• 800 externe Node-Module
• Node.js-Services verarbeiten bis zu 2.000.000 Requests /Minute
Build 2013 - Channel 9June 28, 2013:
„Doug Crockford and Steve Lucco on JavaScript“
Paypal und Node.js• Anforderung:
„Java versus JavaScript“
• Weniger Entwickler, weniger Code (LoC) in der Hälfte der Zeit
• Verdoppelung der Anzahl der Anfragen pro Sekunde (Requests/sec)
• Steigerung der Antwortzeit um 35% auf 200 ms
• Umsetzung von 12 Node.js-Anwendungen in sechs Monaten
• Alle zukünftigen Anwendungen werden in Node.js entwickelt
Bill Scott: “Clash of the Titans: Releasing the Kraken NodeJS @paypal"
http://www.youtube.com/watch?v=tZWGb0HU2QM
Fazit
#dw
x14
Die ersten Erfahrungen mit Node.js
• Weniger Serverkapazitäten
• Weniger Seitenladezeit
• Weniger Entwicklerkapazitäten
• Mehr zufriedene Kunden
• Mehr zufriedene Entwickler
Typische Node.js - Anwendungen
• NoSQL-CRUD
• REST-Architekturen
• Streaming
• Real-Time
• Single-Page-Application
• One Web-App - One-Language
„Das war’s“Viel Spaß noch auf der #DWX14
#dwx14
feed
back
@de
velo
per-w
eek.
de