Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

Latest commit

 

History

History
238 lines (164 loc) · 4.67 KB

slides.md

File metadata and controls

238 lines (164 loc) · 4.67 KB

title: YYCjs Slides output: index.html theme: theme controls: false logo: theme/logo.png

-- title

NodeJS Like a Boss

-- title

Brought to you by

-- presenter

David Luecke

David Luecke

-- presenter

Eric Kryski

Eric Kryski

-- sponsors

Our Sponsors

Assembly

Village Brewery

Startup Calgary

PetroFeed

--

Last Month

  • Un-spaghetti and modularize your code
  • Advanced selectors and DOM traversal
  • Making your code faster
  • Writing your own plugins
  • Introduction to web components and Polymer
  • Data driven views (or why direct DOM manipulation will be a thing of the past)
  • Build web component style applications now with CanJS

--

NodeJS

Node.js is a platform built on Chrome's V8 JavaScript runtime for easily building fast, scalable network applications.

NodeJS logo

  • HTTP/HTTPS
  • TCP/UDP Sockets
  • Event Emitters
  • Streams
  • Files System Access
  • Cross Platform

-- image

How is Node Different?

It uses JavaScript and it has a single threaded event loop. There is a seperate thread pool for IO requests. (Image credited to Elegant Code)

Event Loop

--

Modules

  • currently hosts ~63,000 modules
  • easy to use (npm install <package>)
  • easy to publish (npm publish)
  • use it with anything (folders, tarballs, git repositories)
  • Attempt for JavaScript API standardization

--

CommonJS modules

Provides global module, exports and require() to define this files API

// module1.js
exports.hello = 'World';
// or
module.exports = {
	hello: 'World'
}

Using the module

// main.js
var mod1 = require('./module1');

console.log(mod1.hello); // -> World

--

package.json

CommonJS specification for describing JavaScript packages

{
	"name": "node-up",
	"version": "0.1.0",
	"author": "YYCJS <[email protected]>",
	"description": "Server side JavaScript FTW!",
	"scripts": {
		"test": "mocha test",
		"start": "node lib/main.js"
	},
	"main": "./lib/main.js",
	"repository": {
		"type": "git",
		"url": "https://github.com/yycjs/node-up"
	},
	"dependencies": {
		"somePackage": "> 1.0.0"
	},
	"devDependencies": {
		"some-dev-only-package":  "*"
	},
	"license": "MIT"
}

--

Web Development


Create `example.js` like this:
var http = require('http');
http.createServer(function (req, res) {
	res.writeHead(200, {'Content-Type': 'text/plain'});
	res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

And run it like:

% node example.js
Server running at http://127.0.0.1:1337/

--

Serving Static Files


var http = require("http");
var url = require("url");
var path = require("path");
var fs = require("fs");

http.createServer(function(request, response) {
	var uri = url.parse(request.url).pathname;
	var filename = path.join(process.cwd(), 'assets', uri);
	
	fs.readFile(filename, "binary", function(error, file) {
		if (error) {
			response.writeHead(500, {"Content-Type": "text/plain"});
			response.write(error + "\n");
			return response.end();
		}
		response.writeHead(200);
		response.write(file, "binary");
		response.end();
	});
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

-- image

Express

A sinatra inspired, web application framework. Its sort of the defacto.

Express

-- image

Socket.io

Bringing websockety goodness to your nodejs app. Has fallback to older technologies.

Socket.io

-- image

Feathers

A minimal, real-time, data-driven, wrapper over top of Express that leverages the evented nature of nodejs.

Feathers

--

Next Month

  • Optimizing your JS workflow
  • Modules revisited
  • AMD + RequireJS
  • Component
  • Browserify
  • Grunt
  • Gulp