A brief intro to nodejs
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

A brief intro to nodejs

  • 829 views
Uploaded on

introduction to node.js

introduction to node.js

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
829
On Slideshare
826
From Embeds
3
Number of Embeds
1

Actions

Shares
Downloads
1
Comments
0
Likes
0

Embeds 3

http://ngoding.co 3

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • http://www.developerknowhow.com/why-the-v8-javascript-engine-is-so-good/https://github.com/joyent/node/wiki/ECMA-5-Mozilla-Features-Implemented-in-V8
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/EventLoop
  • http://blog.cloudfoundry.com/2012/06/27/future-proofing-your-apps-cloud-foundry-and-node-js/
  • http://stackoverflow.com/questions/1911015/how-to-debug-node-js-applications?rq=1
  • http://www.jetbrains.com/webstorm/
  • http://stackoverflow.com/questions/1884724/what-is-node-js/6782438#6782438
  • http://stackoverflow.com/questions/1884724/what-is-node-js/6782438#6782438http://perfectionkills.com/whats-wrong-with-extending-the-dom/http://stackoverflow.com/questions/7310521/node-js-best-practice-exception-handling
  • http://stackoverflow.com/questions/1884724/what-is-node-js/6782438#6782438
  • https://github.com/node-inspector/node-inspectorhttp://stackoverflow.com/questions/1911015/how-to-debug-node-js-applications?rq=1
  • http://stackoverflow.com/questions/5062614/how-to-decide-when-to-use-nodejs?rq=1http://nodeguide.com/convincing_the_boss.html
  • https://www.paypal-engineering.com/2013/11/22/node-js-at-paypal/
  • https://github.com/joyent/node/wiki/Resources

Transcript

  • 1. A brief intro to nodejs Jay LJLU from Evenex team
  • 2. • Built on Chrome’s JavaScript runtime • Event-driven • Non-blocking IO • Easily building Fast, scalable network application
  • 3. Built on Chrome’s JavaScript runtime • Server side, V8 engine • Fast • ECMA 5 standards compliance • “api bits that aren’t considered safe to use in a web setting but are built in to node’s V8 engine.” • Choosing JS over C,Lua,Haskell,Ruby
  • 4. Event-driven • EventEmitter • Event loop in libev • Functional programming in JS – First-class functions – Closure • Used across all core modules
  • 5. Non-blocking IO 1/2 • “I/O is expensive”
  • 6. Non-blocking IO 2/2 • Long polling (chatroom/whiteboard), socket.io • Streaming, (Byte)Buffer • Blocking vs non-blocking • Context switch is expensive • C10K problem • Share same architecture with nginx
  • 7. Easily building fast, scalable network application 1/2 • Easy – “NodeJs is the new Java” – Fancy core library – No compile, fast iteration
  • 8. Easily building fast, scalable network application 2/2 • One language rule all. MEAN Stack. • “web”=>“network” • TJ Holowaychuk
  • 9. Engineering • NPM • IDE • Deployment • Coding style • Testing • Debugging • When to use nodejs • Companies using NodeJs
  • 10. Engineering NPM • Node packaged modules – https://npmjs.org – Now part of core node – Easily manage dependencies – package.json
  • 11. Engineering IDE • WebStorm – Commercial license – Truly IDE , good for beginner • Sublime text – Free to use – Syntax highlight – Code template/completion – Node plugin
  • 12. Engineering deployment • Single thread, single process – Utilize my 8 cores CPU ? (new cluster module) • Integrate with legacy services, not replace – Consumes JSON RESTful services • Run behind Nginx – Not stable enough to be a web server • Hosting
  • 13. Engineering coding style • Callback hell – Async.js to rescue • err as first argument – Handle error first ! • Extending prototype – Do not extend the prototypes of any objects, especially native ones
  • 14. Engineering Testing • Mocha – Fancy reports – BDD, TDD – Timeout – good for asyc – Runs in browser as well • CI : grunt+jenkins – Alt : Travis CI https://github.com/travis-ci
  • 15. Engineering debugging • Chrome developer tool – Eclipse based • Node-inspector – Browser based
  • 16. Engineering when to use nodejs • When to use Node.js: • Use Node.js to: • Build a (soft) real-time social app like Twitter or a chat app. • Build high-performance, high I/O, TCP apps like proxy servers, PaaS, databases, etc. • Build backend logging and processing apps. • Build great CLI apps similar to vmc-tool, and build tools such as ant or Make. • Add a RESTful API-based web server in front of an application server. • When NOT to use Node.js: • Node.js is not suitable for every application: • Mission-critical (hard) real-time apps like heart monitoring apps or those that are CPU-intensive. • For simple CRUD apps that don’t have any real-time or high-performance needs, Node.js does not provide much of an advantage over other languages. • Enterprise apps that might need some specific libraries for which there may not be a Node.js library yet. (However, you could build a polyglot app that uses Java in conjunction to Node.js to help with libraries.)
  • 17. Companies using NodeJs • LinkedIn, mobile webapp • Ebay, data retrival gateway • Github, for downloads • Dow Jones & Company, for WJS social site • PayPal (moving every product & every site)
  • 18. Refs and links • http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/ • http://www.slideshare.net/the_undefined/nodejs-best-practices-10428790 • http://www.slideshare.net/the_undefined/nodejs-a-practical-introduction-v2 • http://www.slideshare.net/oscarrenalias/nodejs-for-architects-openslava-2013
  • 19. Getting started !! • git checkout https://github.com/joyent/node • ./configure && make && sudo make install • vi example.js • node example.js
  • 20. Thanks ! • 刘立杰 Jay LJLU
  • 21. More interesting… • CoffeeScript • Twitter Bower • Yeoman/grunt • phantomjs