Section 1

Preview this deck

If the browser makes request from web server (Node) and the web server responded what kind of streams are these?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 14, 2020

Cards (104)

Section 1

(50 cards)

If the browser makes request from web server (Node) and the web server responded what kind of streams are these?

Front

The request is readable and the response is writable, because it is done from the Nodes perspective.

Back

Does greetA and greetB return the same Object? var greetA = require('./greet'); var greetB = require('./greet'); greet.js exports this: module.exports = new Greetr();

Front

They are, because the required returns a cashed Object.

Back

What does the fs module stand for?

Front

File system

Back

Is possible to use the exports without using the module?

Front

Yes, but you have to mutate it. It's recommended to just use module.exports. exports.greet = function() { // code }

Back

What is character encoding?

Front

How characters are stored in binary. (The numbers (or code points) are converted and stored in binary.

Back

What is a chunk?

Front

A piece of data being sent through a stream. (Data is split in 'chunks' and streamed).

Back

What is a template literal?

Front

A way to concatenate strings in JS (ES6). Easier to work with than a bunch of strings concatenated wit '+'. Example: var greet = `Hello ${name}`;

Back

Do the lines below output the same stuff? module.exports exports

Front

Nope, due to by reference exports module points to a new Object.

Back

What is cognitive load?

Front

How many things you have to think about the same time.

Back

What is error-first callback?

Front

Callbacks take an error Object as their first parameter. (null if no error, otherwise will contain an Object defining the error)

Back

What is the revealing module pattern?

Front

Exposing only the properties and methods you want via an returned Object. var greeting = 'Hello world' function greet() { console.log(greeting) } module.exports = { greet: greet }

Back

What is a first-class function?

Front

Everything you can do with other types you can do with functions.

Back

What is a module?

Front

A reusable block of code, whose existence does not accidentally impact other code. JS does not have this (ES6 excluded).

Back

What is a stream?

Front

A sequence of data made available over time. (Pieces of data that eventually combine into a whole)

Back

What two types of events does Node.js have?

Front

System Events <- libuv (C++ Core) Custom Events <- Event Emitter (Javascript Core)

Back

What does Sync stand for? var greet = fs.readFileSync(__dirname + '/greet.txt', 'utf8');

Front

Synchronic approach, this is useful for reading config files.

Back

What is ECMASCRIPT?

Front

The standaard JavaScript is based on.

Back

What is non-blocking?

Front

Doing other things whiteout stopping your program from running.

Back

What is a buffer?

Front

A temporary holding spot for data being moved from one place to another (intentionally limited in size).

Back

What is libuv and what does it do?

Front

It's C++ library that deals with events happening in the operating system.

Back

What does this do? var john = Object.create(person);

Front

It create an empty object named john and inherits all properties and methods from the person Object.

Back

What are magic strings?

Front

A string that has some special meaning in our code. This is a bad practice, because it makes it easy for a typo to cause a bug, and hard for tools to help us find it.

Back

Rewrite this using pipe. var fs = require('fs'); var readable = fs.createReadStream(__dirname + '/greet.txt'); var writable = fs.createWriteStream(__dirname + '/greetcopy.txt'); readable.on('data', function(chunk){ console.log(chunk.length); writable.write(chunk); });

Front

var fs = require('fs'); var readable = fs.createReadStream(__dirname + '/greet.txt'); var writable = fs.createWriteStream(__dirname + '/greetcopy.txt'); readable.pipe(writable);

Back

Match the names of the function types. function greet() { console.log('hi'); } greet(); function logGreeting(fn) { fn(); } logGreeting(greet); var greetMe = function() { console.log('hi'); }; greetMe();

Front

// function statement function greet() { console.log('hi'); } greet(); // functions are first-class function logGreeting(fn) { fn(); } logGreeting(greet); // function expression (still first class) var greeterMe = function() { console.log('hi'); };

Back

What is machine code (lang)?

Front

Programming languages spoken by computer processors. Every program you run on your computer has been converted (compiled) into machine code.

Back

What is an event listener?

Front

It basically code that respond to an event.

Back

A client asks for ... and a server performs ... .

Front

services

Back

Front

Back

What is binary data?

Front

Data stored in binary (sets of 1s and 0s). The core of the math that computers are based on. Each one or zero is called a 'bit' or 'binary digit'.

Back

Let say you have loaded a module using require('./greet.js'); that contains the following code. var greet = function(argument) { console.log('Hello!'); } Is possible to invoke the function expression in app.js?

Front

Nope, this is done by design.

Back

What is a byte?

Front

8 bits, (eight 0s or 1s)

Back

In what lang is Node written?

Front

C++

Back

What is a JS engine?

Front

A program that converts JS code into something the computer processor can understand.

Back

Why is this code running without './' without throwing an error? var util = require('util');

Front

Because it is a native module.

Back

How would you convert this JSON in node to Object and console.log the value of "en"? { "en": "Hello", "es": "Hola" }

Front

var greetings = require('./greetings.json'); console.log(greetings.en);

Back

What will be the output of console.log? var util = require('util'); function Person() { this.firstname = 'John'; this.lastname = 'Doe'; } Person.prototype.greet = function() { console.log('Hello ' + this.firstname + ' ' + this.lastname); } function Policeman() { this.badgenumber = '12345'; } util.inherits(Policeman, Person); var officer = new Policeman(); officer.greet();

Front

Output: Hello undefined undefined utile.inherits just connects the prototypes The function below is never being called. function Person() { this.firstname = 'John'; this.lastname = 'Doe'; } Use: function Policeman() { Person.call(this); // <- this.badgenumber = '12345'; }

Back

How would you make this available outside the module? var greet = function(argument) { console.log('Hello!'); }

Front

module.exports = greet;

Back

In what language are browsers written? Hint: and the DOM

Front

C++

Back

What five arrguments does the IIFE has that is created when a module is exported?

Front

(function (exports, require, module, __filename, __dirname) { // module code })

Back

What encoding is used here? var buf = new Buffer('Hello');

Front

utf8, which is default

Back

How woud read a file greet.txt that is located in the same folder. var fs = require('fs');

Front

var fs = require('fs'); var greet2 = fs.readFile(__dirname + '/greet.txt', 'utf8', function(err, data) { console.log(data); });

Back

How would you load module greet.js that is located in the same folder into the app.js file?

Front

require('./greet.js');

Back

What is a breakpoint?

Front

A spot in our code where we tell a debugging tool to pause the execution of our code.

Back

What is a pipe?

Front

A pipe is connecting two streams by writing to one stream what is being read from another. (In Node you pipe from a Readable stream to a Writable stream)

Back

Why does this work? var buf = new Buffer;

Front

Because Buffer is global in Node.

Back

What is native module?

Front

A module that essentially resides in the lib folder that already given by Node.js.

Back

What is a abstract (base) class?

Front

A type of constructor you never work directly with, but inherit from. ( We create new custom Objects, which inherit from the abstract base class)

Back

What is a character set?

Front

A representation of characters as numbers. Each character gets a number. Unicode and ASCII are character sets.

Back

Front

Back

What are commonJs modules?

Front

An agreed upon standard for how code modules should be structured.

Back

Section 2

(50 cards)

How would you replace the <h1>{Message}</h1> with the 'Hello world'. var http = require('http'); var fs = require('fs'); http.createServer(function(req, res) { res.writeHead(200, { 'Content-type': 'text/html' }); var html = fs.readFileSync(__dirname + '/index.htm'); res.end(html); }).listen(1337, '127.0.0.1');

Front

var http = require('http'); var fs = require('fs'); http.createServer(function(req, res) { res.writeHead(200, { 'Content-type': 'text/html' }); var html = fs.readFileSync(__dirname + '/index.htm', 'utf8'); var message = 'Hello world...'; html = html.replace('{Message}', message); res.end(html); }).listen(1337, '127.0.0.1');

Back

from package.json "dependencies": { "moment": "~2.11.2" } What does the '~' mean?

Front

If a newer patch comes out, then automatically update it.

Back

How would change the Mime type to JSON? res.writeHead(200, { 'Content-type': 'text/html' });

Front

res.writeHead(200, { 'Content-type': 'application/json' });

Back

How would you require a node_module called moment?

Front

var foo = require('moment');

Back

How would you npm install jasmine-node only for development?

Front

npm install jasmine-node --save-dev

Back

What is TCP?

Front

TCP stand for Transmission control protcol. Defines how we send the defined protocol (no matter the protocol type, format). Splits the information into pieces that we are sending through the socket.

Back

Name tree protocols that send data through a socket.

Front

HTTP, FTP, SMTP

Back

check slide

Front

Back

What does ip mean?

Front

Internet protocol

Back

What is a socket?

Front

A internet connection, the line across which the information flows.

Back

What is a endpoint? (API)

Front

One url in a web API. (Sometimes that endpoint (URL) does multiple thing by making choices based on the HTTP request headers.

Back

Rewrite this using streams. var http = require('http'); var fs = require('fs'); http.createServer(function(req, res) { res.writeHead(200, { 'Content-type': 'text/html' }); var html = fs.readFileSync(__dirname + '/index.htm', 'utf8'); res.end(html); }).listen(1337, '127.0.0.1');

Front

var http = require('http'); var fs = require('fs'); http.createServer(function(req, res) { res.writeHead(200, { 'Content-type': 'text/html' }); fs.createReadStream(__dirname + '/index.htm').pipe(res); }).listen(1337, '127.0.0.1');

Back

How would you set view engine to ejs in express?

Front

app.set('view engine' 'ejs');

Back

What is a protocol?

Front

A set of rules two sides agree on to use when communicating. Bothe the client and server are programmed to understand and use that particular set of rules. It is similar to two people from different countries agreeing on a language to peak in.

Back

What standaard ip adres for the local system (localhost)?

Front

127.0.0.1

Back

What is an API?

Front

A set of tools for building a software application. Stands for 'Application Programming Interface'. On the web the tools are usually made available via a set of URLs which accept and send only data via HTTP and TCP/IP.

Back

check slide

Front

Back

How would you install packages specified in package.js?

Front

npm install

Back

What is routing?

Front

Mapping url request to content.

Back

You have created a public folder and want to have static assets be available once browser requests /whatever. How would you do it using express?

Front

app.use('/whatever', express.static(__dirname + '/public'));

Back

How would you serve this JSON on the '/api' url? res.writeHead(200, { 'Content-type': 'application/json' }); var obj = { firstname: 'John', lastname: 'Doe' } res.end(JSON.stringify(obj));

Front

if (req.url ==='/api') { res.writeHead(200, { 'Content-type': 'application/json' }); var obj = { firstname: 'John', lastname: 'Doe' } res.end(JSON.stringify(obj)); }

Back

From what 3 things does a HTTP response consist of?

Front

Status, Headers, Body

Back

How would you respond with a 404 header? http.createServer(function(req, res) { // code here }).listen(1337, '127.0.0.1');

Front

http.createServer(function(req, res) { res.writeHead(404); res.end(); }).listen(1337, '127.0.0.1');

Back

How are the 3 versioning numbers called? 1.7.2

Front

MAJOR.MINOR.PATCH 1.7.2 PATCH - bugs MINOR - new features MAJOR - big changes (code might break) more info: semver.org

Back

What are static files?

Front

Not dynamic, In other words, not precessed by code in any way.

Back

from package.json "dependencies": { "moment": "^2.11.2" } What does the '^' mean?

Front

If a newer minor or patch comes out, then automatically update it.

Back

What does Node 'zlib' module do?

Front

Allows to incorporate a compressed file.

Back

When you npm init, you will get asked to add an entry point. What is that.

Front

This is the file node will run. Mostly it is app.js.

Back

What is a dependency?

Front

Code that another set of code depends on to function. (If you use that code in your app, it is a dependency. Your app depends on it.)

Back

How would you install npm nodemon glabaly?

Front

npm install -g nodemon

Back

Does the native http.js module deal with https?

Front

No there is a separate module for that, https.js as you probably already guest.

Back

What command line should use in order to create a package.json file?

Front

npm init

Back

How would you convert this Object to JSON? var obj = { firstname: 'John', lastname: 'Doe' }

Front

var foo = JSON.stringify(obj);

Back

How can you update npm modules?

Front

npm update

Back

What are environment variables in Node?

Front

Global variables specific to the environment (server) our code is living in. Different servers can have different variable settings, and we can access those values in code.

Back

What is MIMI type?

Front

A standard for specifying the type of data being sent. Stands for 'Multipurpose Internet Mail Extensions'. Examples: application/json, text/html, image/jpeg.

Back

What is http?

Front

A set of rules (and a format) for data being transferred on the web. Stands for 'HyperText Transfer Protocol'. It is a format (of various) defining data being transferred via TCP/IP. Example of a HTPP request: CONNECT www.google.com:443 HTTP/1.1 Host: www.google.com Connection: keep-alive

Back

How would you create a basic server in Node?

Front

var http = require('http'); http.createServer(function(req, res) { res.writeHead(200, { 'Content-type': 'text/plain' }); res.end('Hello world
'); }).listen(1337, '127.0.0.1');

Back

Would work? app.get('/person/:page/:id', function(req, res) { });

Front

Yes, you can have multiple

Back

npm install moment --save What does --save do?

Front

It saves the dependency reference to package.json.

Back

What is middleware?

Front

Code that sits between two layers of software. (In the case of Express, sitting between the request and the response.)

Back

What does next(); do here? app.use('/', function(req, res, next){ console.log('Requst url: ' + req.url); next(); });

Front

Call the next middleware that is connected to this route.

Back

What do the HTTP headers do?

Front

They carry information about the client browser, the requested page, the server and more.

Back

What is a http method?

Front

Specifies the type of action the request wishes to make. (GET, POST, DELETE, and others. Also called verbs.)

Back

What does cli (folder found in node packages) stand for?

Front

command line interface

Back

What does to serialize mean?

Front

To translate an Object into a format that can be stored or transferred. JSON, CSV, XML, and other are popular. 'Deserialize' is the opposite.

Back

check slide

Front

Back

When you talk about npm, you might be talking about two things. What are they?

Front

The registry and ... the program.

Back

What is a port, what does it do?

Front

Once a computer receives a packet, how it knows what program to send it to. When a program is setup on the operating system to receive packets from a particular port, it is said that the program is 'listening' to that port.

Back

Why is good to not store node_modules in repos?

Front

Because we don't need to.

Back

Section 3

(4 cards)

What is express.Router()?

Front

Al it is, is express middleware.

Back

What is the difference between horizontal folder structure and vertical?

Front

http://www.logicmanialab.com/2015/01/mean-js-application-structure.html

Back

What is a session?

Front

A session is a collection of data stored on the server and associated with a given user (usually via a cookie containing an id code)

Back

What is REST?

Front

An architectural style for building APIs. (Stands for 'Representational State Transfer'. We decide that HTTP verbs and URLs mean something.

Back