server-side development Flashcards
what does node.js do
runs js on the server side
what are http methods
textual commands passed via http protocols between the client and the browser
GET
requesting/retrieving content
POST
sending data and retrieving content
what is a web server
software that runs on the server or cloud infrastructure
what does the web server do
handles http requests
listens for tcp connection requests from clients
what is a port
communication endpoints for a host on a network using tcp
how many processes can be assigned to a port at once
1
how many well known ports are there
1023
what is the software loopback ip
127.0.0.1
what are endpoints in node
code intended to receive a request from a client
how can endpoints in node be distinguished
via the url and the http method
node routes
the connection of the http request to the endpoint
response object
what you send back to the client
request object
what came in from the client/browser
an object is created to encapsulate this information
what is AJAX and what does it do
asynchronous javascript and xml; allows content to be updated after loading a page which allows for dynamic pages
happens without intervention from the user
how does AJAX work
after the page has loaded we use js at the client side to query the server
the server responds with content which is processed by js and if we need to the page is updated without being reloaded
why dont we need html in ajax
we dont need to render the page
what is axois
a http client library that runs in browser and on node.js that simplifies querying a web service in js
how do we handle errors in axios
promises; then and catch
what does express do
simplifies handling http requests in js/node.js
url encoded parameters
the simplest way of passing data
how do we pass multiple parameters in url encoded parameters
separating them with &
res.end (express)
ends the response ; nothing else should follow it
res.send (express)
can be used multiple times to construct a response
CORS
cross origin response sharing: a security feature that allows or restricts resources on a web page to be requested from another domain outside the domain where they originated from
what is the difference between GET and http POST
get encodes the data in a url whilst with post the data is encoded in a http request
what is http post used for
sending content of a html form to the server
what does the json parser look like and what is its role
app.use(express.json());
parses the incoming requests
how do we access incoming data with json
const name = req.body.q
when should POST be used and why
when wanting to send data
not ‘visible’ so more secure
no restriction on data length
when should we use GET and what are the downsides of using it
when retrieving web pages
no security
kept in browser history
what is the format of json when sending data using POST
key value pairs
e.g. {“str”: “words”}
what is the role of web sockets
allow you to keep the connection open between the client and server in js so the server can send back data to the client as necessary
how do we set up web sockets on the server
we use a server object to create it
a http connection is ‘upgraded’ to a web socket as requested
we handle the socket like a get (wss.on) and send responses to the client
then disconnect when done (ws.close())
what module is used by node to interact with files
fs
how do we read and send files with node
readFile(filename, callback)
sendFile(filename, callback)
what does _dirname mean when using files
the path where the currently running script is
. (fs module)
current directory
..(fs module)
up a directory
/(fs module)
filesystem root
what is the point of a db
allows you to store and access data efficiently
sql as a relational database
data is in tables
sql as non-procedural
you specify what to do not how to do it
when do we use sqlite
for smaller embedded applications
.verbose() (sqlite)
gives more info on the errors