Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jerry Neal. Agenda ➢ About Node ➢ Modules ➢ Node Architecture ➢ NPM ➢ FAQ ➢ Other Awesome Modules! get ready to node, this session is hands on!

Similar presentations


Presentation on theme: "Jerry Neal. Agenda ➢ About Node ➢ Modules ➢ Node Architecture ➢ NPM ➢ FAQ ➢ Other Awesome Modules! get ready to node, this session is hands on!"— Presentation transcript:

1 Jerry Neal

2 Agenda ➢ About Node ➢ Modules ➢ Node Architecture ➢ NPM ➢ FAQ ➢ Other Awesome Modules! get ready to node, this session is hands on!

3

4 About Node ➢ Open Source, cross-platform runtime environment for server-side and networking applications ➢ Initial Release May 27, 2009 ➢ Created by Ryan Dahl ➢ Stable Release 0.10.33 ➢ http://nodejs.org/, https://github.com/joyent/node http://nodejs.org/https://github.com/joyent/node

5 About Node ➢ Applications are written in JavaScript ➢ Runs on Google’s V8 Engine (same as Chrome) No Browser Quirks!

6 Is Node JS a serious option for enterprise applications? In fact, it’s our best option for typical (heavy data IO) web applications! Let’s see why…

7 Why Node? ➢ Less keystrokes with JS ➢ JS on server and client allows for more code reuse ➢ A lite stack (quick create- test cycle) ➢ Large number of offerings for web app creation Build Fast!

8 Why Node? ➢ Fast V8 Engine ➢ Great I/O performance with event loop! ➢ Small number of layers ➢ Horizontal Scaling Run Fast!

9 Why Node? ➢ JS across stack allows easier refactoring ➢ Smaller codebase ➢ See #1 (Build Fast!) Adapt Fast! “There’s a shift in enterprise IT, unbundling the monolith software packages [at many companies] that has stifled innovation.” - Joe McCann CEO NodeSource

10 Community ➢ Over 2 million downloads per month ➢ NPM averages 211 new modules per day (ruby gems 68 per day, maven 61 per day) ➢ Total Number of npm Packages: 105,109 ➢ Second most stared project on Github ➢ Plus, corporate backing from JoyentJoyent

11 Community

12 Running Node Apps Hands On #1 – ‘Welcome Noder!’

13 Node Globals ➢ process – object providing information and methods for the current process ➢ process.stdout, process.stderr, process.stdin, process.argv, process.env ➢ console – allows printing to stdout and stderr ➢ require() – function to load a module ➢ module – refers to the current module

14 Modules ➢ Modules allow Node to be extended (act as libaries) ➢ We can include a module with the global require function, require(‘module’) ➢ Node provides core modules that can be included by their name: ➢ File System – require(‘fs’) ➢ Http – require(‘http’) ➢ Utilities – require(‘util’)

15 Modules ➢ We can also break our application up into modules and require them using a file path: ➢ ‘/’ (absolute path), ‘./’ and ‘../’ (relative to calling file) ➢ Any valid type can be exported from a module by assigning it to module.exports

16 Modules bar.js module.exports = ‘I am a string’ foo.js var msg = require(‘./bar.js’) console.log(msg) // prints ‘I am a string’

17 Modules bar.js module.exports.hello = function() {return ‘hello’} module.exports.bye = function() {return ‘bye’} foo.js var bar = require(‘./bar.js’) console.log(bar.hello()) // prints ‘hello’ console.log(bar.bye()) // prints ‘bye’

18 Requiring Modules, File System, Args Hands On #2 – ‘Require It’

19 Node Architecture V8 Thread Pool (libeio) Event Loop (libev) Node Bindings (socket, http, etc.) Node Standard Library C C++ JavaScript

20 Node Architecture ➢ Node handles requests with a single thread (the event loop)!

21 Node Architecture ➢ How can this be faster? ➢ Expensive I/O is moved off request thread (in traditional multi-threaded environments, each thread handles the complete request) ➢ Threads are limited by RAM and are expensive to create ➢ Avoids context switching ➢ Allows us to easily write asynchronous code without heavy thread management (synchronization, message passing, etc.)

22 Node Architecture

23 Warning! Be careful to keep CPU intensive operations off the event loop.

24 Http and Streams Hands On #3 – ‘Real Time Data Flow’

25 NPM ➢ Modules can be shared by packaging ➢ Node Package Manager (NPM) is a package manager for node ➢ Command line interface ➢ Public registry www.npmjs.orgwww.npmjs.org ➢ Allows us to install packages from repo, and publish our own

26 NPM ➢ First, we need to create a package.json file for our app ➢ Contains metadata for our app and lists the dependencies ➢ Package.json Interactive Guide Package.json Interactive Guide

27 NPM ➢ Common npm commands: ➢ npm init initialize a package.json file ➢ npm install -g install a package, if –g option is given package will be installed as a global, --save and --save-dev will add package to your dependencies ➢ npm install install packages listed in package.json ➢ npm ls –g listed local packages (without –g) or global packages (with –g) ➢ npm update update a package

28 NPM ➢ SemVar Versions (version [Major].[Minor].[Patch]): ➢ = (default), >, =, <= ➢ * most recent version ➢ 1.2.3 – 2.3.4 version greater than 1.2.3 and less than 2.3.4 ➢ ~1.2.3 most recent patch version greater than or equal to 1.2.3 (>=1.2.3 <1.3.0) ➢ ^1.2.3 most recent minor version greater than or equal to 1.2.3 (>=1.2.3 <2.0.0)

29 Http and Express Hands On #4 – ‘Services’

30 FAQ ➢ V8 engine performs just as good, if not better than jvm ➢ Most ‘intensive’ code is usually due to I/O ➢ If needed, child processes, web workers, and so forth can be used ➢ Of course! As always, be aware of language holes (like ‘eval’) ➢ Node Security Project lists vulnerabilities in packages Node Security Project What about CPU intensive code?Is Node secure?

31 FAQ ➢ Most ‘cryptic’ code is DOM related (ex. selectors) ➢ Preprocessors and ECMAScript 6 bringing more strict typing (and compile time checking) ➢ As always, need standards and best practices! What about code readability/maintenance with JavaScript?

32 FAQ ➢ Built-in Node debugger not great, but IDEs and other tools have the usual debugging experience ➢ V. 0.12 will improve tracing capabilities to allow better performance monitoring, and production grade tools such as New RelicNew Relic Isn’t debugging and production monitoring bad?

33 Other Awesome Modules ➢ koa – middlware using generators koa ➢ async – higher order functions and common patterns for asynchronous code async ➢ lodash – utility library lodash ➢ request – simplified http client request ➢ mongoose – MongoDB ODM mongoose ➢ rethinkdb – driver library for RethinkDB rethinkdb

34 Other Awesome Modules ➢ moment – utilities for dates moment ➢ bluebird – promise based library bluebird ➢ config – runtime configuration config

35 Thanks! http://nodejs.org/ Learn More at


Download ppt "Jerry Neal. Agenda ➢ About Node ➢ Modules ➢ Node Architecture ➢ NPM ➢ FAQ ➢ Other Awesome Modules! get ready to node, this session is hands on!"

Similar presentations


Ads by Google