Upload
designveloper
View
493
Download
0
Tags:
Embed Size (px)
Citation preview
Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Express JS
Web application framework for node
DESIGNVELOPER
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
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
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
Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Hello Express JS application
Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
API Express JS
• APP• REQUEST• RESPONSE• ROUTER
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
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"
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){ // ... });
Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
API Express JS• ROUTER: • var router = express.Router();
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
Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
Thanks you for watching!
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