Express JS

1,239 views

Published on

Websites: https://www.designveloper.com
Visit our blog https://www.designveloper.com/blog
Like Facebook page https://www.facebook.com/designveloper/
Youtube: http://bit.ly/29PTtFS

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,239
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
40
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Express JS

  1. 1. Express JS Web application framework for node Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City DESIGNVELOPER
  2. 2. 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
  3. 3. 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 would Express –css stylus --ejs Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  4. 4. 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
  5. 5. Hello Express JS application Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  6. 6. API Express JS • APP • REQUEST • RESPONSE • ROUTER Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  7. 7. 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
  8. 8. 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
  9. 9. 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
  10. 10. API Express JS • ROUTER: • var router = express.Router(); Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  11. 11. 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
  12. 12. Thanks you for watching! Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  13. 13. Attachment tools Postman – REST Client: https://chrome.google.com/webstore/detail/postman-rest- client/fdmmgilgnpjigdojojpjoooidkmcomcm Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City

×