Full Stack Development Flashcards

1
Q

Express

A

Fast, unopinionated, minimalist web framework for Node.js

With a myriad of HTTP utility methods and middleware at your disposal, creating a robust API is quick and easy.

But First

Blast To The Past

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

Fast, unopinionated, minimalist web framework for Node.js

With a myriad of HTTP utility methods and middleware at your disposal, creating a robust API is quick and easy.

But First

Blast To The Past

A

Express

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

CRUD

A

Create (post) - Make something

Read (get) - Get Something

Update (put) - Change something

Delete (delete) - Remove something

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

Create (post) - Make something

Read (get) - Get Something

Update (put) - Change something

Delete (delete) - Remove something

A

CRUD

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

EJS (Embed Javascript Templates)

A

EJS
(Embedded Javascript Templates)

<h1>Current Rappers</h1>
<ul class="rappers">
<% for(let i=0; i < info.length; i++) {%>
    <li class="rapper">
        <span><%= info[i].stageName %></span>
        <span><%= info[i].birthName %></span>
        <span class="del">delete</span>
    </li>
<% } %>
</ul>

<h2>Add A Rapper:</h2>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

<h1>Current Rappers</h1>

<ul class="rappers">
<% for(let i=0; i < info.length; i++) {%>
    <li class="rapper">
        <span><%= info[i].stageName %></span>
        <span><%= info[i].birthName %></span>
        <span class="del">delete</span>
    </li>
<% } %>
</ul>

<h2>Add A Rapper:</h2>
A

EJS (Embed Javascript Templates)

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

Setting Up The Project

A

mkdir api-project
cd api-project
npm init
npm install express –save
npm install mongodb –save
npm install ejs –save
npm install dotenv –save

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

mkdir api-project
cd api-project
npm init
npm install express –save
npm install mongodb –save
npm install ejs –save
npm install dotenv –save

A

Setting Up The Project

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

let db,
dbConnectionStr = ‘mongodb+srv://demo:demo@cluster0
.2wapm.mongodb.net/rap?retryWrites=true&w=majority’,
dbName = ‘rap’

MongoClient.connect(dbConnectionStr, { useUnifiedTopology: true })
.then(client => {
console.log(Connected to ${dbName} Database)
db = client.db(dbName)
})

A

Connected To DB

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

Connect to DB

A

let db,
dbConnectionStr = ‘mongodb+srv://demo:demo@cluster0
.2wapm.mongodb.net/rap?retryWrites=true&w=majority’,
dbName = ‘rap’

MongoClient.connect(dbConnectionStr, { useUnifiedTopology: true })
.then(client => {
console.log(Connected to ${dbName} Database)
db = client.db(dbName)
})

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

use .env

A

DB_STRING =
mongodb+srv://demo:demo@cluster0.2wapm.mongodb.net/rap?retryWrites=true&w=majority
Use .env
.env file

add .env to .gitignore

.env
node_modules
In terminal, add var to Heroku

heroku config:set DB_STRING =
mongodb+srv://demo:demo@cluster0.2wapm.mongodb.net/rap?retryWrites=true&w=majority

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

DB_STRING =
mongodb+srv://demo:demo@cluster0.2wapm.mongodb.net/rap?retryWrites=true&w=majority
Use .env
.env file

add .env to .gitignore

.env
node_modules
In terminal, add var to Heroku

heroku config:set DB_STRING =
mongodb+srv://demo:demo@cluster0.2wapm.mongodb.net/rap?retryWrites=true&w=majority

A

use .env

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

Connect to DB

A

let db,
dbConnectionStr = process.env.DB_STRING,
dbName = ‘rap’

MongoClient.connect(dbConnectionStr, { useUnifiedTopology: true })
.then(client => {
console.log(Connected to ${dbName} Database)
db = client.db(dbName)
})

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

let db,
dbConnectionStr = process.env.DB_STRING,
dbName = ‘rap’

MongoClient.connect(dbConnectionStr, { useUnifiedTopology: true })
.then(client => {
console.log(Connected to ${dbName} Database)
db = client.db(dbName)
})

A

Connect to DB

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

app.set(‘view engine’, ‘ejs’)
app.use(express.static(‘public’))
app.use(express.urlencoded({ extended: true }))
app.use(express.json())

app.listen(process.env.PORT || PORT, ()=>{
console.log(Server running on port ${PORT})
})

A

Setup Server

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

app.set(‘view engine’, ‘ejs’)
app.use(express.static(‘public’))
app.use(express.urlencoded({ extended: true }))
app.use(express.json())

app.listen(process.env.PORT || PORT, ()=>{
console.log(Server running on port ${PORT})
})

A

Setup Server

17
Q

Create EJS File

A

<h1>Current Rappers</h1>

<ul class="rappers">
<% for(let i=0; i < info.length; i++) {%>
    <li class="rapper">
        <span><%= info[i].stageName %></span>
        <span><%= info[i].birthName %></span>
        <span class="del">delete</span>
    </li>
<% } %>
</ul>

<h2>Add A Rapper:</h2>
18
Q

<h1>Current Rappers</h1>

<ul class="rappers">
<% for(let i=0; i < info.length; i++) {%>
    <li class="rapper">
        <span><%= info[i].stageName %></span>
        <span><%= info[i].birthName %></span>
        <span class="del">delete</span>
    </li>
<% } %>
</ul>

<h2>Add A Rapper:</h2>
A

Create EJS File

19
Q

API GET

A

app.get(‘/’,(request, response)=>{
db.collection(‘rappers’).find().toArray()
.then(data => {
response.render(‘index.ejs’, { info: data })
})
.catch(error => console.error(error))
})

20
Q

app.get(‘/’,(request, response)=>{
db.collection(‘rappers’).find().toArray()
.then(data => {
response.render(‘index.ejs’, { info: data })
})
.catch(error => console.error(error))
})

A

API GET

21
Q

API POST

A

app.post(‘/addRapper’, (request, response) => {
db.collection(‘rappers’).insertOne(request.body)
.then(result => {
console.log(‘Rapper Added’)
response.redirect(‘/’)
})
.catch(error => console.error(error))
})

22
Q

app.post(‘/addRapper’, (request, response) => {
db.collection(‘rappers’).insertOne(request.body)
.then(result => {
console.log(‘Rapper Added’)
response.redirect(‘/’)
})
.catch(error => console.error(error))
})

A

API Post

23
Q

API PUT

A

app.put(‘/addOneLike’, (request, response) => {
db.collection(‘rappers’).updateOne({stageName: request.body.stageNameS,
birthName: request.body.birthNameS,
likes: request.body.likesS},{
$set: {
likes:request.body.likesS + 1
}
},{
sort: {_id: -1},
upsert: true
})
.then(result => {
console.log(‘Added One Like’)
response.json(‘Like Added’)
})
.catch(error => console.error(error))
})

24
Q

app.put(‘/addOneLike’, (request, response) => {
db.collection(‘rappers’).updateOne({stageName: request.body.stageNameS,
birthName: request.body.birthNameS,
likes: request.body.likesS},{
$set: {
likes:request.body.likesS + 1
}
},{
sort: {_id: -1},
upsert: true
})
.then(result => {
console.log(‘Added One Like’)
response.json(‘Like Added’)
})
.catch(error => console.error(error))
})

A

API Put

25
Q

API - DELETE

A

app.delete(‘/deleteRapper’, (request, response) => {
db.collection(‘rappers’).deleteOne({stageName: request.body.stageNameS})
.then(result => {
console.log(‘Rapper Deleted’)
response.json(‘Rapper Deleted’)
})
.catch(error => console.error(error))

})

26
Q

app.delete(‘/deleteRapper’, (request, response) => {
db.collection(‘rappers’).deleteOne({stageName: request.body.stageNameS})
.then(result => {
console.log(‘Rapper Deleted’)
response.json(‘Rapper Deleted’)
})
.catch(error => console.error(error))

})

A

API Delete

27
Q

heroku login -i
heroku create simple-rap-api
echo “web: node server.js” > Procfile
git add .
git commit -m “changes”
git push heroku main

A

Push to Heroku

28
Q

Push to Heroku

A

heroku login -i
heroku create simple-rap-api
echo “web: node server.js” > Procfile
git add .
git commit -m “changes”
git push heroku main

29
Q

npm i express mongoose connect-mongo express-session express-handlebars dotenv method-override moment morgan passport passport-google-oauth20

A

Code to set up beginning of app

30
Q

mkdir todo-mvc-auth-microsoft
cd todo-mvc-auth-microsoft
npm init
npm i connect-mongo dotenv ejs
express express-session mongodb mongoose
nodemon passport passport-azure-ad –save

A
31
Q

DB_STRING =
mongodb+srv://demo:demo@cluster0.2wapm.mongodb.net/rap?retryWrites=true&w=majority
Using .env
.env file

              add .env and config to .gitignore

.env
node_modules
config/config.js
exports.destroySessionUrl = ‘http://localhost:2121’
exports.databaseUri = ‘mongodb://localhost/OIDCStrategy’
Using config
config.js file

const mongoose = require(‘mongoose’)

const connectDB = async () => {
try {
const conn = await mongoose.connect(process.env.DB_STRING, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
})

console.log(`MongoDB Connected: ${conn.connection.host}`)   } catch (err) {
console.error(err)
process.exit(1)   } }

module.exports = connectDB
DB Setup
const express = require(‘express’)
const app = express()
const mongoose = require(‘mongoose’)
const passport = require(‘passport’)
const session = require(‘express-session’)
const MongoStore = require(‘connect-mongo’)(session)
const connectDB = require(‘./config/database’)
const authRoutes = require(‘./routes/auth’)
const homeRoutes = require(‘./routes/home’)
const todoRoutes = require(‘./routes/todos’)

require(‘dotenv’).config({path: ‘./config/.env’})

require(‘./config/passport’)(passport)
Setup Server

DB_STRING = mongodb+srv: //demo:demo@cluster0.2wapm.mongodb.net/rap?retryWrites=true&w=majority Using .env .env file add .env and config to .gitignore .env node_modules config/config.js exports.destroySessionUrl = ‘http://localhost:2121’ exports.databaseUri = ‘mongodb://localhost/OIDCStrategy’ Using config config.js file

A
32
Q

const authRoutes = require(‘./routes/auth’)
const homeRoutes = require(‘./routes/home’)
const todoRoutes = require(‘./routes/todos’)

app.use(‘/’, homeRoutes)
app.use(‘/auth’, authRoutes)
app.use(‘/todos’, todoRoutes)

A
33
Q

API Get

A

app.get(‘/’,(request, response)=>{
db.collection(‘rappers’).find().toArray()
.then(data => {
response.render(‘index.ejs’, { info: data })
})
.catch(error => console.error(error))
})

34
Q

API NEW GET

A

//Routes File
app.use(‘/todos’, todoRoutes)

//Route to Controller
router.get(‘/’, ensureAuth, todosController.getTodos)

//Controller talking to model
getTodos: async (req,res)=>{
console.log(req.user)
try{
const todoItems = await Todo.find()
const itemsLeft = await Todo.countDocuments(
{microsoftId: req.user.microsoftId, completed: false}
)
res.render(‘todos.ejs’,
{todos: todoItems,
left: itemsLeft,
user: req.user}
)
}catch(err){
console.log(err)
}
}

35
Q

Find the hiring manager:
Add them to the hitlist
Follow them on Twitter
Find their email (hunter.io)
Ask for a coffee chat
Send a thank you
Get the recommendation

A