Server side JS Flashcards

1
Q

this keyword

A

Every function has one

this refers to the owner(class)/executor(outer funciton) of the function

global functions refer to the global object

undefined in strict mode

possible to use call to bind this to a specific object…
logMyVar.call(myObj)

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

issues with this

A

anonymous functions are executed globally… so this would refer to the global object.

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

Arrow functions

A

Do not define their own “this” but inherit from their parent. (can be used to fix the anonymous global function problem)

short version of a function
function(x, y) {...} 
(x, y) => ...; or (x, y) => {...};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Immediately Invoked Function Expressions (IIFE) (Definition)

A

Java script function that runs as soon as it is defined.

Ex:
var result = (function () {

})()

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

IIFE Useful for…

A
In this module:
var myPerson = {
    ssid: "12345",
    getSSID: function() {this.logSSIDReq(); return ssid;},
    logSSIDReq: function() { console.log("SSID returned"; }
};

everything is accessable…

can use IIFE to create some privacy!

var myPerson = (function(){
    var ssid= "12345";
    var getSSID= function...
    ...
    return {getSSID: getSSID};
})()

everything is the same except = instead of : and =(function(){})() instead of ={}

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

What is Node.js?

A

JavaScript runtime…

Allows you to run javascript on a server and build command line tools.

No DOM and NO HTML events

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

Node.js modules

A

Some built in modules
-http for making and handling HTTP reqs

  • fs for file i/o
  • crypto for cryptography ops
  • assert for assertions (testing)

Include modules using the require statement
Ex:

var myHttp = require(‘http’)

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

NPM

A

Node Package Manager

Allows to install modules that are not your own and not included in Node.js

Installed modules are included using require()

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

How to share Node software

A

Define an NPM project:

npm init
-also creates a package.json
To install a new module npm install --save [moduleName]
-installs in current dir and saves dependency in package.json

npm install looks up all dependencies in package.json and installs them

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

Express module

A
const express = require('express');
const app = express();

app.get(‘/’, (req, res) => {
res.status(200).send(‘Hello World!’);
});

ETC

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

MongoDB

A

Find documents:
db.collection(“collectionName”).find({}).toArray(function(err, users) {
res.status(200).json(users);
});

also (instead of find):
insertOne()
findOne()
findOneAndUpdate();
deleteMany()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly