While you are waiting, install the following:
We'll write a blog today.
console.log("anything", "any number of things");
var x = 5;
var str = "A string";
var a_bool = true;
var nothing = null;
var arr = [1,2,3,4];
var obj = {
property: "An object attribute",
numerical_property: 1
}
var any_arr = [1, "string", [1,2], {}];
if(correct){
doThis();
}else if(partially_correct){
doThese();
}else{
doThat();
}
switch(a){
case 1:
console.log("eh");
break;
default:
console.log("er");
break;
}
for(var i = 0; i < 10; i++){
console.log(i);
}
function a_func(param1, param2){
console.log(param1 + param2);
}
var a_func = function(param){
console.log("I am a function!", param);
}
var another_same_func = a_func;
a_func();
another_same_func();
function logThreeTimes(msg, callback){
for(var i = 0; i < 3; i++){
console.log(msg);
callback();
}
}
logThreeTimes("my message", function(){
console.log("It just logged");
});
// sync
content = readFile(file1)
doStuffWith(content)
// async
readFile(file1, function(content){
doStuffWith(content);
});
Installs all required libraries locally to your project directory
GET /
app.get("/", function(req, res){
res.send("hello");
});
GET /somepage
app.get("/somepage", function(req, res){
res.send("this is some page");
});
GET /post/:id
app.get("/post/:id", function(req, res){
res.send("This page has id of " +
req.param.id);
});
<html>
<head>
<title> <%= post.title %> </title>
</head>
<body>
<article> <%= post.content %> </article>
</body>
</html>
"<html><head><title>" + post.title + </title></head></html>"
vs
<html>
<head>
<title> <%= post.title %> </title>
</head>
</html>
HTML injection
"<div>" + post.someAttribute + "</div>"
What if
post.someAttribute = "</div><script>doEvil()</script>"
<% (javascript/ ejs command) %>
<%= (javascript to string) %>
// the rest is just html
<% for (var i = 0; i < posts.length; i++){ %>
<%= posts[i].title %>
<% } %>