Advertisement
Fahim_7861

Express Js Note

May 19th, 2021 (edited)
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 KB | None | 0 0
  1. express() methods - app.use(method())
  2.  
  3. 1) express.json() : json format a data get korar jonno
  4.  
  5. 2) express.raw() : stream or buffer format a data get korar jonno
  6.  
  7. 3) express.text() : text format a data get korar jonno
  8.  
  9. 4) express.urlencoded() : form data hisebe data get krtay hole
  10.  
  11. 5) express.static() : static kunu file theke data read korar jonno , example : test.tx or test.html file
  12.  
  13. 6) express.route() : routing ar jonno
  14.  
  15.  
  16.  
  17. Application properties :
  18.  
  19. 1) app.locals : app ar under a local variable declare ar jonno
  20.  
  21. 2) app.mounthpath : mountpath janar jonno , parent path ta janar jonno use hoy
  22.  
  23.  
  24. Events
  25.  
  26. 1) mount : The mount event is fired on a sub-app, when it is mounted on a parent app.
  27.  
  28. Mehotds :
  29.  
  30. 1) app.all() : jaykunu method a hit korlay URL ar sathe millay call hobhe, post ,get ,path any type of method ,
  31. it's like global method
  32.  
  33. 2) app.delete : kunu kichu delete korar jonno use hoy
  34.  
  35. 3) app.disable() : express ar kunu setting k disable krtay use hoy , like case sensitive routing
  36.  
  37. 4) app.enable() : express ar kunu setting k enable krtay use hoy , like case sensitive routing
  38.  
  39. 5) app.enabled('') : kunu setting enable ki na check kortay use hoy , true or false return more ai method
  40.  
  41. 6) app.disabled('') : kunu setting disable ki na check kortay use hoy , true or false return more ai method
  42.  
  43. 7) app.set() : app.set diye kun value set krlay app.get() diye access kora jabe
  44.  
  45. 8) app.get() : data get korar jonno use hoy
  46.  
  47. 9) app.listen() : server start korar jonno
  48.  
  49. 10) app.Method() : Routes an HTTP request, where METHOD is the HTTP method of the request, such as GET, PUT, POST, and so on, in lowercase. Thus, the actual methods are app.get(), app.post(), app.put(), and so on.
  50.  
  51. 11) app.param() : Add callback triggers to route parameters,a kind of middleware of request
  52.  
  53. 12 app.path() : Returns the canonical path of the app, a string.
  54.  
  55. 13) app.post() : kunu kichu post korar jonno
  56.  
  57. 14 ) app.put() : for update any data
  58.  
  59. 15 ) app.use() :
  60.  
  61. 16) app.route() : Returns an instance of a single route, which you can then use to handle HTTP verbs with optional middleware. Use app.route() to avoid duplicate route names (and thus typo errors).
  62.  
  63. 17) app.engine() : model view controller ar jonno use hoy
  64.  
  65.  
  66. Request Object
  67.  
  68. 1) req.baseUrl() : router ar baseUrl ta pawa jabe , j route a achi ai router base ta return korbay
  69.  
  70. 2) req.originalUrl () : original URL ta kokono change hobhe an
  71.  
  72. 3) req.url() : URL ta change hobhe sub URL a gele
  73.  
  74. 4) req.path() : path ta pawa jabe without query parameter
  75.  
  76. 5) req.hostname() : local a run krlay localhost hobhe hostname
  77.  
  78. 6) req.method() : kun method a request kora hoise ai method ar name ta capital letter a pawa jabe
  79.  
  80. 7) req.protocol : j protocol a hit kora hoise ,example : HTTP,https
  81.  
  82. 8) req.params() : request ar parameter ar value pawa jabe
  83.  
  84. 9) req.query() : request ar query object ta return more
  85.  
  86. 10 ) req.body() : request ar body data ta object ar maddomay return korbay , format ta bole ditay hobhe , like json hole : app.use(express.json());
  87.  
  88. 11) req.cookies() : cookies ar data pawa jabe
  89.  
  90. 12) req.secure() : request ta secure ki na check korbay . HTTP hole false and https dile true asbay
  91.  
  92.  
  93. 13) req.app() : different file a app use krtay chailay req.app() diye kora jabe
  94.  
  95. 14) req.route : routing ar detail return krbay
  96.  
  97. 15) req.accepts(value) : kun format a client data accept kore check korar jonno use hoy . example : req.accepts('html')
  98. , req.accepts('application/json')
  99.  
  100. 16) req.get(value) : kunu header ar value ber korar jonno use hoy
  101.  
  102. Response Object
  103. properties :
  104.  
  105. 1) res.app : app ar reference ta return kore
  106.  
  107. 2) res.headerSent : response send kora hoye gele true hobhe otherwise false hobhe
  108.  
  109. 3) res.locals : local variable , kun page render korar somoy data patanur jonno use hoy
  110.  
  111. Method :
  112.  
  113. 4) res.cookie(name,value) : cookie set hobhe
  114.  
  115. 5) res.clearCookie() : cookie clear ar jonno
  116.  
  117. 6) res.end() : response k end kore dey .(data chara send kortay hole res.end() , data send kortay hole res.send()
  118.  
  119. 7) res.send() : HTTP request sent kore with data
  120.  
  121. 8) res.json({ user: 'tobi' }) : json a response fatanur jonno
  122.  
  123. 9) res.status() : status set korar jonno (client ar kache send hobhe , aita sudu status code set krbay )
  124.  
  125. 10 ) res.sendStatus() : status code ta set hoye data hisebe client ar kache chole jabe
  126.  
  127. 11) res.render() : render specific kunu view k render kore
  128.  
  129. 12) res.format() : client j format a data require krtayse oi format a data ready kore dibe , single response function diye amra client ar requirement content type wise data send krtay parbo
  130.  
  131. 13) res.location() : ekta URL send korbay , tokon client bujbay oi URL a redirect krtay hobhe
  132.  
  133. 14) res.redirect() : directly redirect kore dibe client k
  134.  
  135. 15) res.get() : HTTP header ar name return krbay
  136.  
  137. 16) res.set() : header set krtay parbo
  138.  
  139. MIDDLEWARE
  140.  
  141. 1) middleware ekta function
  142.  
  143. 2) execute any code
  144.  
  145. 3) can change req res object
  146.  
  147. 4) can end request response cycle
  148.  
  149. 5) call next middleware by next()
  150.  
  151. 6) throw and catch errors
  152.  
  153.  
  154. Types of middleware :
  155.  
  156. 1) Application-level middleware
  157. 2) Router-level middleware
  158. 3) Error-handling middleware
  159. 4) Built-in middleware. example : app.use(express.json())
  160. 5) Third-party middleware example : app.use(cookieParser())
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement