(6ASI) Week 3

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

Integrating Together (Pt2)

6(ASI)
Week 4
Recap
Recap
Recap
Recap
We want to solve problems,
FAST!
WE ALL WANT TO END THE MISERY QUICKLY!
Advantages of using APIs
● Eliminates human-prone errors as much as possible
● Makes solution-delivery faster
○ Removes the overheads that manually requires more human
efforts to pull-off
● Enables programmers to focus on the problem
○ No longer need to build the tools
Node JS Modules
● Set of functions that are intended to be included in the application
● Comparable to Javascript libraries
○ E.g. importing packages/libraries
● Export:
○ Readies all of your functions to be used by other scripts by
providing the intended function names
● Import:
○ Includes the specified exported functions/packages in the
script
Open Source APIs
Node JS: NPM
● Is an online repository for the publishing
of open-source Node.js projects
● It is also a command-line utility for
interacting with said repository that aids in
package installation, version management,
and dependency management
● https://www.npmjs.com/
How NPM works

Start Here
How NPM works
How NPM works
How NPM works
How NPM works
NPM: Check For Documentation
● Example: Need for formatting dates
○ moment.js
○ https://www.npmjs.com/package/mome
nt
NPM: Check For Documentation
● Installation and usage/tutorials for

packages are often given


○ Especially on bigger Open
Source Libraries

● https://momentjs.com/docs/
[Problem] Get all unique values
● Given a list/array

○ [1,1,1,2,2,3,3,3,4,4,5,5,5,1,6,7,6,7,8,7,9,8,8,9]

● Remove all duplicates


● Needs to be sorted
● Output only the unique value:
○ [1, 2, 3, 4, 5, 6, 7, 8, 9]
[Solution] Get all unique values
● Given a list/array
○ [9, 5, 1,1,1,2,2,3,3,3,4,4,5,5,5,1,6,7,6,7,8,7,9,8,8,9]
● Remove all duplicates
○ Create a loop and another array
○ Iterate per each number and check if the number exists already in the 2nd array
■ If no: write the number
● Needs to be sorted
○ Create a sorting algorithm for the numbers
● Output only the unique value:
○ [1, 2, 3, 4, 5, 6, 7, 8, 9]
[Faster Solution] Use Uniq Package
● https://www.npmjs.com/package/uniq
Activity
● Create a dummy gmail account:
○ 1 Account for the whole section
○ All groups will use the same dummy gmail account
● Install Nodemailer and send an email via nodemailer to a different email account
○ Include NodeJS’s Date() value in the email composition
○ Save screenshots for the run and proof that you sent it
● Save as:
○ Functions: lastname1_lastname2_lastname3_lastname4_functions.js
○ Main File: lastname1_lastname2_lastname3_lastname4_main.js
■ Combined Section
■ Save JS files + Screenshots to zip
References
● https://nodejs.org/en/knowledge/getting-started/npm/what-is-npm/
● https://github.com/moment/moment
● https://github.com/mikolalysenko/uniq

You might also like