Full Stack Development Flashcards
Express
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
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
Express
CRUD
Create (post) - Make something
Read (get) - Get Something
Update (put) - Change something
Delete (delete) - Remove something
Create (post) - Make something
Read (get) - Get Something
Update (put) - Change something
Delete (delete) - Remove something
CRUD
EJS (Embed Javascript Templates)
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>
<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>
EJS (Embed Javascript Templates)
Setting Up The Project
mkdir api-project
cd api-project
npm init
npm install express –save
npm install mongodb –save
npm install ejs –save
npm install dotenv –save
mkdir api-project
cd api-project
npm init
npm install express –save
npm install mongodb –save
npm install ejs –save
npm install dotenv –save
Setting Up The Project
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)
})
Connected To DB
Connect to DB
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)
})
use .env
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
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
use .env
Connect to DB
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)
})
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)
})
Connect to DB
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}
)
})
Setup Server