EJS Flashcards

1
Q

What is EJS?

A

Templating language that lets you generate HTML markup with plain JavaScript
Useful when you want to use a single HTML page, but with different contents/data based on conditions

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

Creating your first EJS Template

A
npm install ejs
In .js,
app.set(‘view engine’, ‘ejs’);
Create a new folder called ‘views’
Add a file with .ejs
.ejs file follows HTML format, but has ejs variable placeholders
Placeholder marker

To display a ejs webpage,
res.render(>);

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

Running Code Inside the EJS Template

A

We can add JavaScript code in the EJS file.
Each line of the JavaScript needs to have an EJS scriptlet of
Use scriptlet only for control-flow, but only in select situations.
Most logic needs to reside in the server code

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

Passing Data from Your Webpage to Your Server

A
  1. This will be done via a POST request from the web page.
  2. Server, let’s say app.js, will then handle the POST request.
  3. It can use body-parser, to then obtain the data being sent, and work with the data
    res. redirect()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The Concept of Scope in the Context of Javascript

A

Variables inside of a function, have local scope to that function
Variables outside of a function, have global scope
If/Else or For/While
Variable created will have global scope
let will have local scope
const will have local scope
Use let or const whenever you can, over var

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

Adding Pre-Made CSS Stylesheets to your Website

A

All files that will be used must be served up in express app.js, these are static files
Static files are files that clients download as they are from the server.

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

Understanding Templating vs Layouts

A

Templating
Used mainly when you want to reuse the structure and format of a web page, but changing the data within them

Layouts
When you want to reuse certain parts of a webpage, like the headers, footers, and styling, in many different webpages

But overall, the body structure differs
Use for reusing parts of the webpage
Reused component pages are called partials

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

Understanding Node Module Exports: How to Pass Functions and Data Between Files

A

Using functions between files:
Node.js contains an object called module
If you want to create functions in a class that you want it to be reusable in other files:
You can set module.exports. =
module.exports can also be shortened down, and exports can be used

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

To use the function:

A

Create a reference variable, and link it to the file where the reusable functions reside
Be sure to use __dirname + if it’s custom, because we didn’t install using npm

Then invoke the function using .

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

Blog Website Challenge

A

Usually, the npm packages that are being used are gitignored, and when a new person works with the project they would then initially go ahead and run npm install
Express Parameter Routing
Lodash

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