MERN Flashcards

1
Q

What is MERN?

A

A development stack. It stands for MongoDB, Express, Node.js, and React.js

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the main HTTP requests to a REST API?

A

GET, POST, PUT, PATCH, DELETE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Difference between REST and graphQL API?

A

REST have multiple endpoints, graphQL typically have only one. graphQL uses query paramaters to differientiate between different kinds of request

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Two different ways of connecting React and Node.

A

Combined: runs on the same server and uses a single domain name.

Decoupled: runs on seperate servers each with their own domain names. Is more responsive than Combined app.

Rendered: The server renders its own html.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

API

A

Application programming interface

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

SPA

A

Single Page Application

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why don’t we connect React directly to MongoDB?

A

It is a security concern, because doing so would expose sensitive information to the front end which anyone would be able to read.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How many servers are typically involved in a MERN application

A

Three servers. One that runs REACT, one that runs the backend API (NODE.js, EXPRESS) and one that runs the MongoDB data base.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to make a post request to the backend from the frontend?

A

const response = await fetch(‘http//:localhost:3000/api/users/signup’,{
method:’POST’,
headers:{
‘Content-Type’:’application/json’,
},
body:JSON.stringify({
name:formState.inputs.name.value,
email:formState.inputs.email.value,
password:formState.inputs.password.value
})

const responseData = await response.json()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a CORS error?

A

CORS cross origin resource sharing, is a security concept enforced by the browser

The same-origin policy is very restrictive. Under this policy, a document (i.e., like a web page) hosted on server A can only interact with other documents that are also on server A. In short, the same-origin policy enforces that documents that interact with each other have the same origin.

An origin is made up of the following three parts: the protocol, host, and port number.

Resources on a server should only be shared or accessed by requests coming from the same server or origin.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to set CORS headers middleware on the Express server?

A

//Needs to be set before the routes are defined.

server.use((req,res,next)=>{
    //Which domains should have access
    res.setHeader(
        'Access-Control-Allow-Origin',
        '*'
    );
    //Which Headers requests may have
    res.setHeader(
        'Access-Control-Allow-Headers',
        'Origin, X-Requested-With, Content-Type, Accept, Authorization'
    );
    //Which methods requests may include
    res.setHeader(
        'Access-Control-Allow-Methods',
        'GET, POST, PATCH, DELETE'
    );
    next();
});
How well did you know this?
1
Not at all
2
3
4
5
Perfectly