13
Express JS Web application framework for node Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City DESIGNVELOPER

Express JS

Embed Size (px)

Citation preview

Page 1: Express JS

Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

Express JS

Web application framework for node

DESIGNVELOPER

Page 2: Express JS

Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

What We need to start Express js?

• Knowledge• Javascript basic• Node js basic

• Using some component support for Express• Backbone JS ( MVC Client )• Template Engine Javascript: ejs, jade, mustache• MongoDb, MySQL

Page 3: Express JS

Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

How to setup Express JS?• npm install (if var dependencies express version )• npm install [-g] express ( lastest version )• Express:• -h, --help : Show help command• -V, --version : Version of express• -s, --sessions : Add support session for Express• -e, --ejs : Use template engine is ejs (default: jade)• -J, --jshtml : Use template engine is jshtml (default: jade)• -H, --hogan: Use template engine is jshtml (default: jade)• -c, --css: (less/stylus) (default: css)

If you want to generate an application with ejs and Stylus support you wouldExpress –css stylus --ejs

Page 4: Express JS

Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

Run Express JS Application?

• Use: node [project_main_js_file]Ex: node app.js

Page 5: Express JS

Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

Hello Express JS application

Page 6: Express JS

Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

API Express JS

• APP• REQUEST• RESPONSE• ROUTER

Page 7: Express JS

Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

API Express JS• Application

var express = require('express'); var app = express();• App.set(name,value): Assigns setting name to value.• App.get(name): Get setting name value.• app.use([path], function): Use the given middleware

function, with optional mount path, defaulting to "/".• Application Router• app.VERB(path, [callback...], callback)• VERB: Http verbs: GET, POST, PUT, DELETE

Page 8: Express JS

Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

API Express JS• REQUEST• Req.params• GET: /user/:name , req.params.name name

• Req.query • GET: search?q=abc, req.query.q abc

• Req.param• // ?name=abc, req.param('name') abc• // POST name=abc, req.param('name') // “abc“• /user/:name with req: //user/abc

req.param('name') // => “abc"

Page 9: Express JS

Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

API Express JS

• RESPONSE• res.send([body|status], [body])• res.send({ some: 'json' }); • res.send('some html'); • res.send(404, 'Sorry, we cannot find that!'); • res.send(500, { error: 'something blew up' });• res.send(200);

• res.render(view, [locals], callback)• res.render('index', function(err, html){ // ... });

Page 10: Express JS

Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

API Express JS• ROUTER: • var router = express.Router();

Page 11: Express JS

Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

Building Application REST ful with Express Js• Understand to start application nodejs with Express js• Create module and require it• Render view in express• Router express

Developing more:• Backbonejs• MongoDb

Page 12: Express JS

Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

Thanks you for watching!

Page 13: Express JS

Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

Attachment tools

Postman – REST Client:

https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm