Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.
For the best experience please use the latest Chrome, Safari or Firefox browser.
All About
Node.js
An adventure in backend javascript.
Node.js is a server-side javascript runtime based on Google Chrome's javascript engine (V8).
Node.js is highly concurrent. It is based on the principle of non-blocking I/O. This achieved using the event loop pattern.
Two Approaches to I/O
Performance Comparison
Node.js, in short, performs suprisingly well - despite some of the stigma that Javascript usually attracts.
But the real reson that Node.js is so popular is its, ease of use. Node makes programming simple. This makes it a great language for prototyping and hackathons.
Basic Node.js Example
Node.js Modules
- Every *.js file is a module
- Modules can export internal functions and variables with the exports object
- The require(...) function gives access to the exports of other modules
Node.js Modules (cont.)
- Modules are singletons - there is exactly one copy of each module
- Modules are encapsulated - the variables and functions in a module can only be accessed by that module
Node.js Packages
- Packages are a collection of Node.js modules
- Packages usually expose more complex, polished and complete functionality and/or information
- e.g. XML Parser = Module; RSS Reader = Package
Node.js Packages (cont.)
- Packages are defined by the package.json file
- package.json describes name, description, repository, author(s) and dependencies of a module
But how do we keep track of all the packages that people write?
Node.js Package Manager
- NPM is a repository for millions of node packages
- It's also a command line tool for managing dependencies
- NPM comes bundled with node - it's an integral part of node.js development
Using NPM
- npm init to create your own new package; this creates a package.json automagically
- npm install --save <PACKAGE_NAME> to install an npm package as a dependency to your package
Using NPM (cont.)
- Use npm uninstall --save <PACKAGE_NAME> to uninstall an npm package dependency
- Use npm publish to publish your package to npm
- Visit http://npmjs.org to search for npm packages
Common Uses of Node.js
- Node.js is used most often as a web server; the most popular web server package for node is express
- Node.js can be used for build tools (e.g. grunt and gulp)
- Node.js is also used for command line tools (e.g. coffeescript compiler)
Live Coding Demo
Building a Node.js Webserver in less than 30 minutes
Happy Hacking!