Please enable JavaScript.
Coggle requires JavaScript to display documents.
Node.js & Express Essentials - Coggle Diagram
Node.js & Express
Essentials
routing
used for handling REST API
usage
basic
make sure the express app is instantiated
schema
app.METHOD(PATH, CONTROLLER)
app.get('/', (req, res) => {res.send('hey')})
chaining controllers
app.METHOD(PATH, [controlelr1, controller2, ...controllerN])
router object
instantiate the router object
router.get, etc instead of using app
use case
paired with middlewares dedicated to
a particular set of routes
middlewares
used to process request/response on all request of a particular scope
usage
basically just like
routing
with additional
next
argument
binding
application-level
router-level
use
keyword
JWT authentication & authorization
main idea
"give a man a passport, and make him show that passport everytime they want to do things"
terminologies
secret
gives service to
refresh token
main idea
used to get new
access token
(access token will expire)
longer duration than
access token
must be stored securely!
storage ideas
access token
main idea
token that is given upon authentication, and required for every authorization
identifies the user
best practices
should have expiration duration
main idea
allows randomization per every app/server
access token & refresh token should have different
secret
stored in
ENV variable
bearer
patterns
first, user authenticate themselves and get
access token
along with
refresh token
on every resource request, they send with
access token
if it returns and invalid token, make the client send a request to auth server to obtain new
access token
given a
refresh token
sequelize orm
creating connection
create a new sequelize object
models
migrating models
sync method
available core arguments
force
alter
creating models
define the model
remember to export
relations
using ES6
why ES6?
allows you to use
import * from ''
statement
using
babel
install babel & its preset
pro & cons
a lot of pros
only one cons:
availaibility
resolved by using
babel
using typescript
why use typescript?
type friendly
scalable
new team could adapt quickly
steps to install
install
dev
dependencies
typescript
ts-node
configure ts.config.json
configure
babel
to add
typescript
preset
testing with
jest
steps to install
install
jest
as
dev
dependency
configure jest.config.js
run tests normally
note
read documentation to match
jest
with
babel