@@ -40,7 +40,7 @@ Create folder day1--> go folder by Cd command -> Now type
4040 it will ask you ceratin detail, either you can provide details or just click on enter.
4141Now you can see the package.json file on the folder.
42425 . Create file Index.js
43- write ``` rubyconsole .log("Hello world")``` in index.js.
43+ write ``` console .log("Hello world")``` in index.js.
44446 . Go to terminal window, go to day1 folderand type
4545> node index.
4646 you will get the output in terminal.
@@ -129,23 +129,25 @@ Some other global object are
129129
130130ExpressJs use to build the Node Application, it make faster the devlopment and provide inbuild code for development.<br /><br />
131131
132- 1 . You can know more details about expressjs from https://expressjs.com/ <br />
132+ 1 . You can know more details about expressjs from ``` https://expressjs.com/ ``` <br />
133133
1341342 . Tag of express Js is well suited "Fast, unopinionated, minimalist web framework for Node.js"<br />
135135
1361363 . install express by <br />
137- // npm install express --save<br /><br />
137+ ``` ruby
138+ npm install express -- save
139+ ```
138140
139141
1401424 . You can see the below code, previously when we have checked for http, it took many line of code to see in browser.<br />
141143// you can get same code on expressjs website. <br /><br />
142-
144+ ``` ruby
143145const ex = require (" express" );< br / >
144146const app = ex();< br / >< br / >
145147
146148app.get(' /' , (req, res) => { res.send(' Hello world' ); })< br / >
147149app.listen(" 4000" , () => console.log(" Server is running on port 4000" ));< br / >< br / >
148-
150+ ```
149151
1501524 . With expressJs you can create Web application, Middleware (API).<br />
151153Which is easier to interagte with application.<br /><br />
@@ -155,7 +157,7 @@ Which is easier to interagte with application.<br /><br />
155157// You can see how to handle the routing using the express JS like get/post<br />
156158// you can see below for more details about routing.<br />
157159// https://expressjs.com/en/starter/basic-routing.html <br /><br />
158-
160+ ``` ruby
159161< h3> Index .js < / h3>
160162
161163========================< br / >
@@ -173,7 +175,7 @@ app.get('/Books', (req, res) => { res.send('Book selves'); })<br />
173175app.post(' /Books/NewBook' , (req, res) => { res.send(' Book selves' ); })< br / >< br / >
174176
175177app.listen(" 4000" , () => console.log(" Server is running on port 4000" ));< br / >
176-
178+ ```
177179
178180# Day 11 - Express App Generator
179181
@@ -182,25 +184,25 @@ app.listen("4000", () => console.log("Server is running on port 4000"));<br />
1821842 . I installed the nodeJsexpression from node.js commond prompt.
183185
1841863 . For more details about express applocation generation you can see the below URL.
185- https://expressjs.com/en/starter/generator.html
187+ ``` https://expressjs.com/en/starter/generator.html ```
186188
1871894 . It provide the step by step way to do that.
188190
1891915 . After installed it successfully, used below command to get the application template.
190- > express E:\node_tutorial\day11-ExpressAppGenerator
192+ ``` express E:\node_tutorial\day11-ExpressAppGenerator ```
191193
192- 6 . Move to > cd E:\node_tutorial\day11-ExpressAppGenerator
194+ 6 . Move to ``` cd E:\node_tutorial\day11-ExpressAppGenerator ```
193195
1941967 . Now run the application as below.
195197
1961988 . Now get the template of pug instade of creating blank and default template.
197- > express --view=ejs E:\node_tutorial\day11-ExpressAppGenerator
199+ ``` express --view=ejs E:\node_tutorial\day11-ExpressAppGenerator ```
198200
1992019 . Than install all the packages
200- > npm install
202+ ``` npm install ```
201203
20220410 . Now we run the application by.
203- > SET DEBUG=day11-expressappgenerator:* & npm start
205+ ``` SET DEBUG=day11-expressappgenerator:* & npm start ```
204206
20520711 . It create all the structure of application which is required.
206208a) Public -- Whch is work like assets folder having image, Script and style locations.
@@ -210,9 +212,9 @@ c) View -- All application view.
21021212 . To add any view or update the any view you need to check the view file.
211213
212214
213- index.ejs
215+ < b > index.ejs </ b >
214216
215- =========================
217+ ``` ruby
216218
217219< !DOCTYPE html>
218220< html>
@@ -225,14 +227,13 @@ index.ejs
225227 < p >< %= message %> </p>
226228 < / body>
227229< / html>
228- ====================
230+ ```
229231
230232 In above you can see the title and Message is binding dynamically and it is passing from the routes file.
231233
232234
233- Routes/Index.js
234-
235- ===========================
235+ <b >Routes/Index.js </b >
236+ ``` ruby
236237 var express = require (' express' );
237238var router = express.Router ();
238239
@@ -242,8 +243,7 @@ router.get('/', function(req, res, next) {
242243}) ;
243244
244245module.exports = router;
245-
246- =============================
246+ ```
247247
248248Here you can see the Title is satya and Message is 'Welcome to NodeJs exress'
249249you can see it in browser as.
@@ -260,7 +260,7 @@ you can see it in browser as.
2602603. If you will not include the middleware, it will not show the static file you included to project.
261261
2622624. Lets include express js in application similar way we did it on day 10
263- // npm install express --save
263+ ``` npm install express --save```
264264
2652655. Lets create folder starature with the name assets and having sub folder. <br/ >
266266- Images : It contain images.
@@ -271,8 +271,7 @@ you can see it in browser as.
2712717. Lets see HTML file structure with Image and CSS.
272272
273273<b>index.html </b>
274-
275- ===========================
274+ ```ruby
276275html <br/>
277276title<br/>
278277 My static Page
@@ -293,12 +292,12 @@ body<br/>
293292/body<br/><br/>
294293
295294/html<br/>
296-
295+ ```
2972968. Now include the middleware component in Index.js as below.
298297
299- Index.js
298+ <b> Index.js</b>
300299
301- ======
300+ ```ruby
302301const ex = require(" express" );
303302const app = ex();
304303
@@ -310,6 +309,7 @@ app.get('/', (req, res) => { res.sendfile("index.html"); })
310309
311310
312311app.listen(" 4000 " , () => console.log(" Server is running on port 4000 " ));
312+ ```
313313
314314 9. Output you will get in the screen as.
315315
@@ -325,20 +325,19 @@ app.listen("4000", () => console.log("Server is running on port 4000"));
3253254. Routing refers how the and what values we can send to endpint URL trough client.
3263265. Based on the endpoint input application will behave.
327327 You can also refer to below URL of express for more details.
328- https://expressjs.com/en/guide/routing.html
328+ ``` https://expressjs.com/en/guide/routing.html```
329329
3303306. The following code is an example of a very basic route. <br /><br />
331331
332- < b >
332+ ```ruby
333333var express = require('express')
334334var app = express()
335335
336336// respond with " hello world" when a GET request is made to the homepage<br />
337337app.get('/', function (req, res) {
338338 res.send('hello world')
339339})
340-
341- </b ><br /><br />
340+ ```
342341
3433427. Mostly there are two way method for roting Get and post but it is allowing All also.
344343
@@ -347,73 +346,72 @@ app.get('/', function (req, res) {
347346 b. The characters ?, +, *, and () are subsets of their regular expression counterparts
348347 c. The route path will match requests to about. <br />
349348
350- < b >
349+ ```ruby
351350app.get('/about', function (req, res) {
352351 res.send('about')
353352 })
354-
355- </b ><br /><br />
353+ ```
356354
3573559. This route path will match acd and abcd. Either b or not.<br />
358356
359- < b >
357+ ```ruby
360358app.get('/ab?cd', function (req, res) {
361359 res.send('ab?cd')
362360 })
363- </ b >< br />< br />
361+ ```
364362
365- 10 . This route path will match abcd, abxcd, abRANDOMcd, ab123cd, and so on.
363+ 10. This route path will match ``` abcd, abxcd, abRANDOMcd, ab123cd, ``` and so on.
366364front (ab) and last(cd) and in between any random text you can put.<br />
367365
368- < b >
366+ ```ruby
369367app.get('/ab*cd', function (req, res) {
370368 res.send('ab*cd')
371369 })
372- </ b >< br />< br />
370+ ```
373371
374372 11. This route path will match abcd, abbcd, abbbcd, and so on. You can place mutiple time b.<br />
375- < b >
373+ ```ruby
376374 app.get('/ab+cd', function (req, res) {
377375 res.send('ab+cd')
378376 })
379- </ b >< br />< br />
377+ ```
380378
381379 12. <b>Route parameters</b>
382380 Passing the parameter on Route URL
383381 You need to define the Route URL like below.
384382 Input http://localhost:4000/users/50
385- output {"userId":"50"}<br />
383+ ``` output {" userId" :" 50 " }<br />```
386384
387- < b >
385+ ```ruby
388386 app.get('/users/:userId', function (req, res) {
389387 res.send(req.params)
390388})
391- </ b >< br />< br />
389+ ```
392390
39339113. If you want passing value whould not mandatory than you can use<br />
394392
395- < b >
393+ ```ruby
396394app.get('/users/:userId?', function (req, res) {
397395 res.send(req.params)
398396})
399- </ b >< br />< br />
397+ ```
400398
40139914. You can pass the mutiple paramnter on route URL as like below.
402400Input http://localhost:4000/users/50/books/5
403- Output {"userId":"50","bookId":"5"} < br />
401+ ``` Output {" userId" :" 50 " ," bookId" :" 5 " }```
404402
405- < b >
403+ ```ruby
406404 app.get('/users/:userId/books/:bookId', function (req, res) {
407405 res.send(req.params)
408406 })
409- </ b >< br />< br />
407+ ```
410408
411409 15. You can seperate the parameters also by using -
412410 Input value for that http://localhost:4000/flights/hyderabad-Cg
413- output {"from":"hyderabad","to":"Cg"} < br />
411+ ``` output {" from" :" hyderabad" ," to" :" Cg " } ```
414412
415- < b >
413+ ```ruby
416414 app.get('/flights/:from-:to', function (req, res) {
417415 res.send(req.params)
418416 })
419- </ b >< br />
417+ ```
0 commit comments