Presenters: Matt Walters & Sahat Yalkabov
- Get up and running with nvm/n, npm, Node.js and Express.
- Learn fundamental Node and JavaScript concepts like callbacks, events, and promises.
- Become familiar with some of Node's most popular modules and learn their benefits.
- Bootstrap a site and API with the latest tools like yeoman, bower, and others.
- Deploy your site to heroku or a cloud of your choice.
- Teach you where to look in order to more easily understand and learn Node on your own.
- install node
- have an editor installed
- numbers, arrays, objects (which are just associative arrays), & functions (which are just a special type of object)
- asynchronous - callbacks, events & promises
- variable scope, hoisting, closures
- use strict
- the event loop
- Joint Walkthrough Coding: Exploring and getting used to different code control flow techniques for asynchronous calls in JS.
- Pro Tip: refer to https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript
- More Learning: http://nodeschool.io/#functionaljs
- Understanding V8
- Understanding the Event Loop & async IO
- node, repl, files
- The CommonJS Module System
- node core - quick intro - http & events
- Pro Tip: nvm or n
- Joint Walkthrough Coding: Writing a simple version of curl, using only the 'http' module
- More Learning: http://nodeschool.io/#learn-you-node
- npm init, search, info, install (& -g), update, home
- --save, --save-dev
- semver
- node_modules + echo "node_modules" >> .gitignore
- Node.js module-making mantras (small, tested, single purpose, compose-able)
- npm publish
- Pro Tip: npm link
- Pro Tip: re-use private modules using github tarballs in package.json
- Problem: Rewrite previous example using 'request'. Be sure you save its dependency in package.json
- console, process, events, stream, http, util, child_process
- events - on vs once, 'error' and 'uncaughtException'
- streams! like unix pipes, in code - readable, writeable, duplex, transform
- Pro Tip: https://github.com/isaacs/readable-stream
- Problems:
- Copy curl implementation and update to use 'readable' event and read() method from stream api
- Copy previous solution and change to use pipe() to automatically control back pressure.
- More Learning: http://nodeschool.io/#stream-adventure
- 'npm home express', connect, jade
- 'npm home underscore' (or lodash), async, bluebird
- 'npm home mocha', request, mongoose, passport.js
- Pro Tip: Favor modules that do one thing, but do it well. Compose these modules into larger modules and solutions.
- Pro Tip: Navigating and learning to use modules - View the tests and examples!
Problem:
-
- Create a simple express app that lets you upload an image, which is then shown to the user. (To complete this you'll create a simple express site, add routes and views which present a form to a user and accept a multipart POST from the form.)
- Bonus 1) use the 'gm' module to resize your images upon upload to save a thumbnail as well as original message.
- Bonus 2) use the 'async' module to create three different sizes of your uploaded image.
More Learning:
- 'npm home yeoman'
- 'npm home bower'
- 'npm home browserify'
- 'npm home gulp'
- 'npm home http-proxy'
Problems:
-
- Install yeoman, install the 'browserify' generator and generate a new site. Choose gulp when asked to do so. (if you have issues with SASS, redo and choose not to install when generating).
-
- Update the site you just created to make an ajax call back to the server. Do a GET request to a new route in your site and return a random word to the browser. When received in the browser, update the page to say Hello+Your_Word instead of 'Hello World'. Make the random-word-swap happen every time someone clicks the 'Learn more' button. User browserify to keep your code well organized.
-
- Separate your API from your site by creating a new express site and a proxy using http-proxy. Keep each in a separate folder and start each individually, on different ports. Use a regular expression to have your proxy direct all requests with a url including '/api' to the api, and all other requests to your site.
- adding a Procfile
- starting multiple executables
Problem:
- create a Procfile, heroku create, git push heroku master
async.waterfall([
function(callback) {
callback(null, 'one', 'two');
},
function(arg1, arg2, callback) {
// Here arg1 is 'one' and arg2 is 'two'
callback(null);
},
], function(err, results) {
// Optional callback when everything is finished
});
var os = require('os');
var cluster = require('cluster');
cluster.setupMaster({
exec: 'app.js'
});
cluster.on('exit', function(worker) {
console.log('Worker ' + worker.id + ' died');
cluster.fork();
});
for (var i = 0; i < os.cpus().length; i++) {
cluster.fork();
}