Express.js Flashcards

1
Q

What is Express?

A

A node framework, that was built to make programmers write less repetitive code
Built specifically for web developers

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

Creating Our First Server with Express

A
npm init
npm install express
In the server.js File
//jshint esversion:6
Place this comment above to remove warnings
const express = require(‘express’);
Function that represents the express module, and gets binded to the variable app
const app = express();
Listen to a specific port
app.listen(3000);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Handling Requests and Responses: the GET Request

A
localhost:3000
Equivalent to the root of a home page
Root Page
Browser sends a GET request to the server
app.get(, )
Example
app.get(“/”, function(req, res) {});
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Understanding and Working with Routes

A

app.get(, )
Specifies the route that we are going to respond to
When a route is encountered, the get() is executed

Path
Example:
Root Path
“/”

Responds for the specifies Route
Example:
function(req, res) {
res.send();

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

Nodemon.io

A

Will monitor for changes in your js code and will automatically change your code
Activate nodemon
nodemon

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

Responding to Requests with HTML Files

A
res.sendFile()
\_\_dirname
Gives the current file path
Usage:
\_\_dirname + “”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Processing POST Requests with Body Parser

A
has an action and a method
method
POST, so we are sending data somewhere
action
Path/location to interact with (Like sending data via a POST)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

app.post(, )

A

Specifies that when there is a POST request for the route, the callback method will be executed

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

body-parser

A
Used to parse incoming POST data
To install, call the command “npm install body-parser”
In the JS file, include
const bodyParser = require(‘body-parser’);
app.use(bodyParser);
body-parser Modes
app.use(bodyParser.)
bodyParser.text()
Parse all the requests into text/string
bodyParser.json()
bodyParser.urlencoded()
Used when parsing data that is sent via a HTML form
bodyParser.urlencoded({extended: true})
Allows us to POST nested objects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Javascript Starter Template

A

Please see the attached screenshot

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