Start up theory: npm modules with an eye on Express.js

3 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€43.60
List Price:  €61.05
You save:  €17.44
£37.75
List Price:  £52.86
You save:  £15.10
CA$69.02
List Price:  CA$96.63
You save:  CA$27.61
A$71.52
List Price:  A$100.14
You save:  A$28.61
S$64.06
List Price:  S$89.69
You save:  S$25.63
HK$391.44
List Price:  HK$548.05
You save:  HK$156.60
CHF 39.65
List Price:  CHF 55.52
You save:  CHF 15.86
NOK kr487.21
List Price:  NOK kr682.13
You save:  NOK kr194.92
DKK kr327.18
List Price:  DKK kr458.09
You save:  DKK kr130.90
NZ$86.55
List Price:  NZ$121.18
You save:  NZ$34.62
د.إ183.58
List Price:  د.إ257.03
You save:  د.إ73.45
৳6,133.73
List Price:  ৳8,587.72
You save:  ৳2,453.98
₹4,626.09
List Price:  ₹6,476.90
You save:  ₹1,850.81
RM196.88
List Price:  RM275.65
You save:  RM78.77
₦69,278.72
List Price:  ₦96,995.75
You save:  ₦27,717.03
₨13,957.23
List Price:  ₨19,541.24
You save:  ₨5,584.01
฿1,626.85
List Price:  ฿2,277.73
You save:  ฿650.87
₺2,207.80
List Price:  ₺3,091.10
You save:  ₺883.29
B$266.49
List Price:  B$373.10
You save:  B$106.61
R843.97
List Price:  R1,181.63
You save:  R337.65
Лв85.64
List Price:  Лв119.90
You save:  Лв34.26
₩75,058.98
List Price:  ₩105,088.58
You save:  ₩30,029.60
₪157.19
List Price:  ₪220.08
You save:  ₪62.89
₱2,978.75
List Price:  ₱4,170.49
You save:  ₱1,191.73
¥7,985.65
List Price:  ¥11,180.55
You save:  ¥3,194.90
MX$897.33
List Price:  MX$1,256.33
You save:  MX$359
QR181.70
List Price:  QR254.40
You save:  QR72.69
P681.14
List Price:  P953.66
You save:  P272.51
KSh6,465.42
List Price:  KSh9,052.10
You save:  KSh2,586.68
E£2,616.47
List Price:  E£3,663.27
You save:  E£1,046.80
ብር7,802.54
List Price:  ብር10,924.18
You save:  ብር3,121.64
Kz45,840.83
List Price:  Kz64,180.83
You save:  Kz18,340
CLP$45,862.38
List Price:  CLP$64,211
You save:  CLP$18,348.62
CN¥344.76
List Price:  CN¥482.69
You save:  CN¥137.93
RD$3,071.01
List Price:  RD$4,299.66
You save:  RD$1,228.65
DA6,630.47
List Price:  DA9,283.19
You save:  DA2,652.72
FJ$111.41
List Price:  FJ$155.98
You save:  FJ$44.57
Q383.33
List Price:  Q536.69
You save:  Q153.36
GY$10,457.82
List Price:  GY$14,641.79
You save:  GY$4,183.96
ISK kr6,313.73
List Price:  ISK kr8,839.73
You save:  ISK kr2,526
DH470.79
List Price:  DH659.14
You save:  DH188.35
L872
List Price:  L1,220.88
You save:  L348.87
ден2,686.37
List Price:  ден3,761.13
You save:  ден1,074.76
MOP$402.95
List Price:  MOP$564.17
You save:  MOP$161.21
N$839.30
List Price:  N$1,175.09
You save:  N$335.79
C$1,839.29
List Price:  C$2,575.15
You save:  C$735.86
रु7,382.41
List Price:  रु10,335.96
You save:  रु2,953.55
S/172.37
List Price:  S/241.34
You save:  S/68.96
K215.81
List Price:  K302.16
You save:  K86.34
SAR187.60
List Price:  SAR262.66
You save:  SAR75.05
ZK972.95
List Price:  ZK1,362.21
You save:  ZK389.25
L223.08
List Price:  L312.33
You save:  L89.25
Kč1,071.29
List Price:  Kč1,499.89
You save:  Kč428.60
Ft17,200
List Price:  Ft24,081.38
You save:  Ft6,881.37
SEK kr473.94
List Price:  SEK kr663.55
You save:  SEK kr189.61
ARS$69,754.96
List Price:  ARS$97,662.53
You save:  ARS$27,907.56
Bs345.41
List Price:  Bs483.60
You save:  Bs138.19
COP$184,073.20
List Price:  COP$257,717.21
You save:  COP$73,644.01
₡23,518.56
List Price:  ₡32,927.87
You save:  ₡9,409.30
L1,323.15
List Price:  L1,852.52
You save:  L529.36
₲322,483.56
List Price:  ₲451,502.79
You save:  ₲129,019.22
$U2,018.88
List Price:  $U2,826.59
You save:  $U807.71
zł187.35
List Price:  zł262.31
You save:  zł74.95
Already have an account? Log In

Transcript

Now we are going to introduce some NPM modules that we need to use the very beginning of our code. Even if later during the course we are going to install other NPM modules. Let's start with the most important probably that is the Express. For framework that is defined as a fast minimalist web framework for note, you can check all the details on Express js.com. So how does it work? The first thing we have to do is to create an express application as shown.

And the very basic operation we can do is to just listen on a specific port for example 5000, as shown in this slide. Before going to see how to handle an HTTP request with experts. We have to introduce the concept of middleware function that is defined as a function that has access to the request object called v rec by convention and the response object called rest, by convention, and the next function in the applications request response cycle. The next function is a function in the Express router, which, when invoked, executes the middleware succeeding the current middleware. So how do we handle HTTP requests? For example, let's see how we can get a specific route.

So what we are going to do is to use the app, the Express app and call the get method to perform a get request. We specify our route URL, and we provide the middleware function. So in this case, dot get represents the HTTP method for which the middleware function applies. The route is a path. That by convention is called route in the experts world for which the middleware function applies the middleware arguments. The first is an HTTP request argument.

The second one is the HTTP response argument. And the third one is the callback. In the same way, we can perform a POST request as shown in the slide. The second module, I will I would like to introduce this body parser that is our no GS body parser middleware. I am not going to go through these definitions, but these two are the function we are going to use. Please check it in the resources I'm leaving in the web page.

The third one stripe of course, the stripe node library provides convenient access to the stripe API from applications written in the server side JavaScript. Please note server side. This is a library only for server side JavaScript.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.