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
€42.65
List Price:  €59.71
You save:  €17.06
£36.89
List Price:  £51.65
You save:  £14.76
CA$68.53
List Price:  CA$95.95
You save:  CA$27.42
A$76.53
List Price:  A$107.14
You save:  A$30.61
S$63.78
List Price:  S$89.30
You save:  S$25.51
HK$392.41
List Price:  HK$549.40
You save:  HK$156.99
CHF 39.92
List Price:  CHF 55.89
You save:  CHF 15.97
NOK kr503.76
List Price:  NOK kr705.30
You save:  NOK kr201.54
DKK kr318.18
List Price:  DKK kr445.47
You save:  DKK kr127.29
NZ$82.55
List Price:  NZ$115.58
You save:  NZ$33.02
د.إ183.58
List Price:  د.إ257.03
You save:  د.إ73.45
৳6,111.42
List Price:  ৳8,556.48
You save:  ৳2,445.05
₹4,274.59
List Price:  ₹5,984.77
You save:  ₹1,710.18
RM211.38
List Price:  RM295.95
You save:  RM84.57
₦77,171.56
List Price:  ₦108,046.36
You save:  ₦30,874.80
₨14,180.91
List Price:  ₨19,854.41
You save:  ₨5,673.50
฿1,621.55
List Price:  ฿2,270.30
You save:  ฿648.75
₺1,995.08
List Price:  ₺2,793.27
You save:  ₺798.19
B$274.25
List Price:  B$383.97
You save:  B$109.72
R893.69
List Price:  R1,251.24
You save:  R357.55
Лв83.53
List Price:  Лв116.95
You save:  Лв33.41
₩68,209.40
List Price:  ₩95,498.62
You save:  ₩27,289.21
₪169.21
List Price:  ₪236.91
You save:  ₪67.70
₱2,827.83
List Price:  ₱3,959.19
You save:  ₱1,131.36
¥7,299.28
List Price:  ¥10,219.58
You save:  ¥2,920.29
MX$941.06
List Price:  MX$1,317.56
You save:  MX$376.50
QR181.99
List Price:  QR254.80
You save:  QR72.81
P668.06
List Price:  P935.34
You save:  P267.27
KSh6,473.70
List Price:  KSh9,063.70
You save:  KSh2,590
E£2,483.99
List Price:  E£3,477.79
You save:  E£993.79
ብር6,761.14
List Price:  ብር9,466.14
You save:  ብር2,705
Kz45,840.83
List Price:  Kz64,180.83
You save:  Kz18,340
CLP$46,543.04
List Price:  CLP$65,163.98
You save:  CLP$18,620.94
CN¥358.55
List Price:  CN¥502
You save:  CN¥143.45
RD$2,976.90
List Price:  RD$4,167.90
You save:  RD$1,191
DA6,449.49
List Price:  DA9,029.80
You save:  DA2,580.31
FJ$112.06
List Price:  FJ$156.90
You save:  FJ$44.83
Q384.29
List Price:  Q538.04
You save:  Q153.74
GY$10,449.69
List Price:  GY$14,630.40
You save:  GY$4,180.71
ISK kr6,055.51
List Price:  ISK kr8,478.20
You save:  ISK kr2,422.69
DH452.22
List Price:  DH633.14
You save:  DH180.92
L839.82
List Price:  L1,175.81
You save:  L335.99
ден2,623.70
List Price:  ден3,673.39
You save:  ден1,049.69
MOP$404.07
List Price:  MOP$565.73
You save:  MOP$161.66
N$893.32
List Price:  N$1,250.72
You save:  N$357.40
C$1,839.63
List Price:  C$2,575.63
You save:  C$736
रु6,836.74
List Price:  रु9,571.99
You save:  रु2,735.24
S/177.35
List Price:  S/248.31
You save:  S/70.95
K206.63
List Price:  K289.30
You save:  K82.67
SAR187.48
List Price:  SAR262.49
You save:  SAR75.01
ZK1,183
List Price:  ZK1,656.30
You save:  ZK473.29
L216.75
List Price:  L303.46
You save:  L86.71
Kč1,054.87
List Price:  Kč1,476.90
You save:  Kč422.03
Ft17,020.68
List Price:  Ft23,830.31
You save:  Ft6,809.63
SEK kr474.35
List Price:  SEK kr664.13
You save:  SEK kr189.78
ARS$59,370.03
List Price:  ARS$83,122.79
You save:  ARS$23,752.76
Bs345.26
List Price:  Bs483.40
You save:  Bs138.13
COP$201,851.43
List Price:  COP$282,608.16
You save:  COP$80,756.72
₡25,202.33
List Price:  ₡35,285.28
You save:  ₡10,082.94
L1,307.23
List Price:  L1,830.23
You save:  L522.99
₲398,753.76
List Price:  ₲558,287.18
You save:  ₲159,533.41
$U2,009.55
List Price:  $U2,813.53
You save:  $U803.98
zł180.89
List Price:  zł253.27
You save:  zł72.37
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.