node.js workshop

36
Node Meetup Tuesday, December 2, 2014

Upload: hengki-sihombing

Post on 17-Aug-2015

74 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Node.JS Workshop

Node MeetupTuesday, December 2, 2014

Page 2: Node.JS Workshop

$ whoiam

Page 3: Node.JS Workshop

{ name : “Hengki Sihombing” email : “[email protected]”, twitter : “hengkiardo”, github : “aredo” }

module.export =

Page 4: Node.JS Workshop

Kickstarter Your Node.JS Application

http://blog.efvincent.com/wp-content/uploads/2011/06/Capture.png

Page 5: Node.JS Workshop

require(‘express’) require(‘mongoose’) require(‘passport’) require(‘async’) require(‘grunt’) require(‘demo’) require(‘QA’)

Page 6: Node.JS Workshop

Why Node.JS

Page 7: Node.JS Workshop

Answer by your selfWhy you come to this meetup :)

Page 8: Node.JS Workshop

Express.JSFast, unopinionated, minimalist web framework for Node.js

expressjs.com

$ npm install express

Page 9: Node.JS Workshop

MVC Framework base on Express.JS

http://www.quora.com/Why-should-I-use-Express-when-developing-a-web-app-with-Node-js http://evanhahn.com/understanding-express/

• KrakenJs http://locomotivejs.org/ • Locomotive.JS http://locomotivejs.org/

• Sails http://locomotivejs.org/ • Sleek.JS http://sleekjs.com/ • ……

Page 10: Node.JS Workshop

Why Express.JS ???

http://www.quora.com/Why-should-I-use-Express-when-developing-a-web-app-with-Node-js http://evanhahn.com/understanding-express/

• Express is a lightweight framework, meaning it does not make too many assumptions but gives you enough to avoid re-inventing the wheel.

• Express is preferred because it adds dead simple routing and support for Connect middleware, allowing many extensions and useful features

• Like any abstraction, Express hides difficult bits and says "don't worry, you don't need to understand this part". It does things for you so that you don't have to bother. In other words, it's magic

• https://www.google.com/#q=why+express.js

Page 11: Node.JS Workshop

Simple Express App

Page 12: Node.JS Workshop

Why Mongoose ?

• Because it provides easy-to-use methods for interacting with MongoDB. It is ORM, actually. It helps you forget about driver's query documentation, and focus on your models.

• Mongoose provides a straight-forward, schema-based solution to modeling your application data and includes built-in type casting, validation, query building, business logic hooks and more, out of the box.

• Mongoose provides various functionalities which makes your life easy such as

Page 13: Node.JS Workshop

MongoDB Connection with Mongoose

Page 14: Node.JS Workshop

• 140+ authentication strategies • Easily handle success and failure • Supports persistent sessions • Dynamic scope and permissions • Pick and choose required strategies • Implement custom strategies • Lightweight code base

•Easy To Use!!

https://github.com/jaredhanson/passport

Page 15: Node.JS Workshop

Sample Twitter Auth with Passport

Page 16: Node.JS Workshop

Sample FB Auth with Passport

Page 17: Node.JS Workshop

Sample Linkedin Auth with Passport

Page 18: Node.JS Workshop

ASYNCHRONOUSBecause Javascript

Page 19: Node.JS Workshop

PromisesPromises… Promises… Never break your promises.

Personally, never make promises.

https://blog.domenic.me/youre-missing-the-point-of-promises

Page 20: Node.JS Workshop

😟

Page 21: Node.JS Workshop

Not part of the Node“until latest stable version”

Makes in tegrat ion more d i f f icu l t . Makes swapping code in / out more painfu l .

So good i t ’s got i t ’s own websi te cal lbackhel l .com

Callbacks

Page 22: Node.JS Workshop

async

$ npm install async — save

Async is a utility module which provides straight-forward, powerful functions for working with

asynchronous JavaScript. Although originally designed for use with Node.js, it can also be

used directly in the browser.

https://github.com/caolan/async

Page 23: Node.JS Workshop
Page 24: Node.JS Workshop
Page 25: Node.JS Workshop
Page 26: Node.JS Workshop

Why use a task runner or

build system?

another build tools: Gulp, Make, NPM, Ant, Maven

Page 27: Node.JS Workshop

Automation

Page 28: Node.JS Workshop

Automation isn’t about being lazy.

It’s about being efficient

Page 29: Node.JS Workshop
Page 30: Node.JS Workshop
Page 31: Node.JS Workshop
Page 32: Node.JS Workshop

$ npm install -g grunt-cli

Before you get started

$ npm install —save-dev grunt

Page 33: Node.JS Workshop

package.json to manage dependencies

Page 34: Node.JS Workshop

Grunt Overview

Page 35: Node.JS Workshop

Demo

https://express4-bootstrap-starter.herokuapp.com/

https://github.com/aredo/express4-bootstrap-starter

$ git clone [email protected]:aredo/express4-bootstrap-starter.git

Page 36: Node.JS Workshop

QA!

{ name : “Hengki Sihombing” email : “[email protected]”, twitter : “hengkiardo”, github : “aredo” }

module.export =