Refactoring our code: where we are

2 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.91
List Price:  €61.47
You save:  €17.56
£37.57
List Price:  £52.60
You save:  £15.03
CA$69.20
List Price:  CA$96.89
You save:  CA$27.68
A$78.29
List Price:  A$109.61
You save:  A$31.32
S$65.57
List Price:  S$91.80
You save:  S$26.23
HK$387.84
List Price:  HK$543.02
You save:  HK$155.17
CHF 41.25
List Price:  CHF 57.75
You save:  CHF 16.50
NOK kr521.14
List Price:  NOK kr729.64
You save:  NOK kr208.50
DKK kr327.81
List Price:  DKK kr458.96
You save:  DKK kr131.15
NZ$83.64
List Price:  NZ$117.11
You save:  NZ$33.46
د.إ183.61
List Price:  د.إ257.07
You save:  د.إ73.46
৳6,073.20
List Price:  ৳8,502.97
You save:  ৳2,429.76
₹4,262.65
List Price:  ₹5,968.05
You save:  ₹1,705.40
RM218.60
List Price:  RM306.06
You save:  RM87.46
₦80,783.34
List Price:  ₦113,103.14
You save:  ₦32,319.80
₨14,040.59
List Price:  ₨19,657.95
You save:  ₨5,617.35
฿1,671.56
List Price:  ฿2,340.32
You save:  ฿668.76
₺1,915.61
List Price:  ₺2,682.01
You save:  ₺766.39
B$286.42
List Price:  B$401.01
You save:  B$114.59
R935.31
List Price:  R1,309.52
You save:  R374.20
Лв85.98
List Price:  Лв120.38
You save:  Лв34.40
₩71,757.29
List Price:  ₩100,465.95
You save:  ₩28,708.65
₪182.42
List Price:  ₪255.41
You save:  ₪72.98
₱2,824.65
List Price:  ₱3,954.74
You save:  ₱1,130.09
¥7,121.15
List Price:  ¥9,970.18
You save:  ¥2,849.03
MX$979.36
List Price:  MX$1,371.19
You save:  MX$391.82
QR182.01
List Price:  QR254.84
You save:  QR72.82
P682.85
List Price:  P956.04
You save:  P273.19
KSh6,468.70
List Price:  KSh9,056.70
You save:  KSh2,588
E£2,547.33
List Price:  E£3,566.46
You save:  E£1,019.13
ብር6,707.64
List Price:  ብር9,391.24
You save:  ብር2,683.59
Kz45,590.88
List Price:  Kz63,830.88
You save:  Kz18,240
CLP$47,128.72
List Price:  CLP$65,983.99
You save:  CLP$18,855.26
CN¥364.27
List Price:  CN¥510.01
You save:  CN¥145.74
RD$2,965.28
List Price:  RD$4,151.63
You save:  RD$1,186.35
DA6,614.76
List Price:  DA9,261.20
You save:  DA2,646.43
FJ$112.99
List Price:  FJ$158.20
You save:  FJ$45.20
Q385.02
List Price:  Q539.06
You save:  Q154.03
GY$10,457.37
List Price:  GY$14,641.15
You save:  GY$4,183.78
ISK kr6,362.72
List Price:  ISK kr8,908.32
You save:  ISK kr2,545.60
DH462.67
List Price:  DH647.77
You save:  DH185.10
L863.61
List Price:  L1,209.12
You save:  L345.51
ден2,701.63
List Price:  ден3,782.50
You save:  ден1,080.86
MOP$399.49
List Price:  MOP$559.32
You save:  MOP$159.82
N$928.29
List Price:  N$1,299.68
You save:  N$371.39
C$1,839.41
List Price:  C$2,575.32
You save:  C$735.91
रु6,827.25
List Price:  रु9,558.70
You save:  रु2,731.44
S/184.84
List Price:  S/258.79
You save:  S/73.95
K203.84
List Price:  K285.39
You save:  K81.55
SAR187.51
List Price:  SAR262.53
You save:  SAR75.02
ZK1,418.30
List Price:  ZK1,985.74
You save:  ZK567.43
L218.55
List Price:  L305.98
You save:  L87.43
Kč1,098.33
List Price:  Kč1,537.76
You save:  Kč439.42
Ft17,897.03
List Price:  Ft25,057.28
You save:  Ft7,160.24
SEK kr480.89
List Price:  SEK kr673.28
You save:  SEK kr192.39
ARS$58,161.84
List Price:  ARS$81,431.23
You save:  ARS$23,269.39
Bs345.39
List Price:  Bs483.57
You save:  Bs138.18
COP$214,982.32
List Price:  COP$300,992.45
You save:  COP$86,010.13
₡25,136.27
List Price:  ₡35,192.79
You save:  ₡10,056.52
L1,295.82
List Price:  L1,814.26
You save:  L518.43
₲399,838.47
List Price:  ₲559,805.85
You save:  ₲159,967.38
$U2,096.30
List Price:  $U2,934.99
You save:  $U838.69
zł187.97
List Price:  zł263.17
You save:  zł75.20
Already have an account? Log In

Transcript

Now, let's focus on what we have right now. After some refactoring before continuing with adding features. As you can see, we now use the EMP file to store even the server port. We are going to take back this info in the config.js file that we are going to import in the index.js file. We have now introduced our routes file to have some structure behind the roots of our web application, and to not have these routes hard coded in the index.js file. We are going to use it here right now in the app dot get function.

So after this little refactoring our articles class will contain methods to return the list of all the articles in our static list that returns a promise with the success response with the payload set to all the articles, then we have a function that will return the article indentified by an article id or an error if the article id does not match any article id. And after this refactoring our index.js file looks like this. So we are using routes that are not anymore coded. We are using the functions that will handle success response and error response, respectively, thanks to the definitions in the response management but what they will Like to I mean, I would like to focus on the introduction of body parser. We are not going to see the theory and the details, as I already said before, but what is important here is to understand is that for our past requests, we need the req dot body, dot body object, that by default, it's undefined.

And it's populated using body parser middleware, such as body parser. So thanks to body parser the req dot body object which contains key value pairs of data supplemented in the request body

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.