Express Flashcards

1
Q

What is a framework?

A

Embodies the concept of Inversion of Control (IoC).
Fill in white spaces.
Framework Calls You

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

Process to setup Express

A
> npm install express --save
var express = require("express")
var app = express();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

start express

A

app.listen(PORT, IP, function)

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

define a get route in express

A

app.get(‘/route-path’, function (request, response) {});

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

Express

how to return something in get request

A

within call back function call response.send(content)

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

Express

How do you define a route that matches routes not specified

A

at the end place:

app.get(‘*’, function(req, res) {});

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

Express

How do you define url path variables

A

use colon + var_name

app.get(‘/r/:subreddit/comments/:id

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

Express

Using route params

A

app.get(‘/r/:subreddit/comments/:id, function(req, res){})

you access subreddit and id via req.params.subreddit and req.params.id respectively

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

What does EJS stand for?

A

Embedded Javascript

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

Express

How do you return a template in a route callback

A

res.render(“template/path”)

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

Is EJS natively supported by express?

A

No. you need to install with npm, but you don’t need to require it because you don’t call it directly.

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

Express

How do you pass and use a variable to EJS template in Express?

A

In express file
res.render(‘template.ejs’, {varName: var})

In template.ejs

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

What types of ejs tags are there?

A

render content to html

evaluate but don’t render

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

Express

How do you pass data in from a form to the server?

A
  • set form action to the post route
  • install npm package body-parser
    var bodyparser = require(‘body-parser’)
    app.use(bodyparser.urlencoded({extended:true}));
    app.post(‘/route’, function(req, res) {
    req.body
    })
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Express

How can you prevent from having to retype the .ejs for each template?

A

app.set(“view engine”, “ejs”);

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

Express

Forward to another route

A

app.redirect(‘/route’)