Skip to content

Commit 77e5095

Browse files
Update README.md
1 parent 079c1d8 commit 77e5095

1 file changed

Lines changed: 50 additions & 52 deletions

File tree

README.md

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
4141
Now you can see the package.json file on the folder.
4242
5. Create file Index.js
43-
write ```rubyconsole.log("Hello world")``` in index.js.
43+
write ```console.log("Hello world")``` in index.js.
4444
6. 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

130130
ExpressJs 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

134134
2. Tag of express Js is well suited "Fast, unopinionated, minimalist web framework for Node.js"<br />
135135

136136
3. install express by <br />
137-
// npm install express --save<br /><br />
137+
```ruby
138+
npm install express --save
139+
```
138140

139141

140142
4. 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
143145
const ex = require("express");<br />
144146
const app = ex();<br /><br />
145147

146148
app.get('/', (req, res) => { res.send('Hello world'); })<br />
147149
app.listen("4000", () => console.log("Server is running on port 4000"));<br /><br />
148-
150+
```
149151

150152
4. With expressJs you can create Web application, Middleware (API).<br />
151153
Which 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 />
173175
app.post('/Books/NewBook', (req, res) => { res.send('Book selves'); })<br /><br />
174176

175177
app.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 />
182184
2. I installed the nodeJsexpression from node.js commond prompt.
183185

184186
3. 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

187189
4. It provide the step by step way to do that.
188190

189191
5. 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

194196
7. Now run the application as below.
195197

196198
8. 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

199201
9. Than install all the packages
200-
> npm install
202+
```npm install```
201203

202204
10. Now we run the application by.
203-
> SET DEBUG=day11-expressappgenerator:* & npm start
205+
``` SET DEBUG=day11-expressappgenerator:* & npm start ```
204206

205207
11. It create all the structure of application which is required.
206208
a) Public -- Whch is work like assets folder having image, Script and style locations.
@@ -210,9 +212,9 @@ c) View -- All application view.
210212
12. 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');
237238
var router = express.Router();
238239

@@ -242,8 +243,7 @@ router.get('/', function(req, res, next) {
242243
});
243244
244245
module.exports = router;
245-
246-
=============================
246+
```
247247
248248
Here you can see the Title is satya and Message is 'Welcome to NodeJs exress'
249249
you can see it in browser as.
@@ -260,7 +260,7 @@ you can see it in browser as.
260260
3. If you will not include the middleware, it will not show the static file you included to project.
261261
262262
4. 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
265265
5. 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.
271271
7. Lets see HTML file structure with Image and CSS.
272272
273273
<b>index.html </b>
274-
275-
===========================
274+
```ruby
276275
html <br/>
277276
title<br/>
278277
My static Page
@@ -293,12 +292,12 @@ body<br/>
293292
/body<br/><br/>
294293
295294
/html<br/>
296-
295+
```
297296
8. Now include the middleware component in Index.js as below.
298297
299-
Index.js
298+
<b>Index.js</b>
300299
301-
======
300+
```ruby
302301
const ex = require("express");
303302
const app = ex();
304303
@@ -310,6 +309,7 @@ app.get('/', (req, res) => { res.sendfile("index.html"); })
310309
311310
312311
app.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"));
325325
4. Routing refers how the and what values we can send to endpint URL trough client.
326326
5. 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
330330
6. The following code is an example of a very basic route. <br /><br />
331331
332-
<b>
332+
```ruby
333333
var express = require('express')
334334
var app = express()
335335
336336
// respond with "hello world" when a GET request is made to the homepage<br />
337337
app.get('/', function (req, res) {
338338
res.send('hello world')
339339
})
340-
341-
</b><br /><br />
340+
```
342341
343342
7. 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
351350
app.get('/about', function (req, res) {
352351
res.send('about')
353352
})
354-
355-
</b><br /><br />
353+
```
356354
357355
9. This route path will match acd and abcd. Either b or not.<br />
358356
359-
<b>
357+
```ruby
360358
app.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.
366364
front (ab) and last(cd) and in between any random text you can put.<br />
367365
368-
<b>
366+
```ruby
369367
app.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
393391
13. If you want passing value whould not mandatory than you can use<br />
394392
395-
<b>
393+
```ruby
396394
app.get('/users/:userId?', function (req, res) {
397395
res.send(req.params)
398396
})
399-
</b><br /><br />
397+
```
400398
401399
14. You can pass the mutiple paramnter on route URL as like below.
402400
Input 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

Comments
 (0)