Node.JS Flashcards

CodeWithMosh

1
Q

Node is a framework?

TRUE / FALSE

A

FALSE

Node is a run time environment for executing JS code

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

Node works Synchronise or Asynchronise

A

Asynchronise

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

Node is good for?

  • CPU intensive sites
  • I/O disk network access apps
A

I/O disk network access apps

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

how to run a JS file in node?

A

node “name of file”

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

how to start node in terminal?

A

node

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

how to end node in terminal?

A

control+c twice

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

in node there is no window object

TRUE / FLASE

A

TRUE

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

window.console.log();

Write the above for Node

A

global.console.log

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

there is no window object in NODE instead we use the keyword _______

A

global

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
var message = ' ';
console.log(global.message); 
//returns in NODE?
A

undefined

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

every file in node is considered a _____

A

module

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

to load a module we use the ______ keyword

A

require

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

require(‘./logger’);

convert to new ES6 syntax

A

import ‘./logger’;

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

what we used to indicated current folder

A

./

period slash

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

when using node as best practice what should be changed?

var logger = require(‘./logger’);

console. log(logger);
logger. log(“hello”);

A

var to const

loading module when importing use const so it does not change

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

variables and functions are scoped to the ______

A

modules

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

what is not valid and why?

exports.log = log;
module.exports.log = log;
exports = log;

A

//this exports is a reference to module.exports function

exports = log;

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

The path module provides utilities for working with file and directory paths. It can be accessed using:

const path = _________(‘path’);

A

require

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

The ________ module provides utilities for working with file and directory paths.

A

path

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

The _________ module provides a number of operating system-related utility methods.

A

OS

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

The os module provides a number of operating system-related utility methods. It can be accessed using:

const os = ________

A

const os = require(‘os’);

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

The ______ module provides an API for interacting with the file system in a manner closely modeled around standard POSIX functions

A

fs

filesystem

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

const fs = ________

A

const fs = require(‘fs’);

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

when using File System Module there are Asynchronous and Synchronous methods, what should we generally use?

A

Asynchronous or non blocking

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

Asynchronous is associated with blocking or non-blocking

A

non-blocking

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

Synchronous is associated with blocking or non-blocking

A

blocking

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

const fs = require(‘fs’);

const files = fs.readdirSync(____)

A

./

dot slash

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

all async methods take a_____ as the last element

A

function

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

a name for a signal that something has happened

A

event

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

The events module name is always capilatized because its a __________

A

class

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

events module are?

 - functions
 - class
 - variables
A

class

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

emit means

A

make a noise or produce a signal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q
const EventEmitter = require('events');
const emitter = new EventEmitter();
emitter.emit('messageLogged');

the code above won’t do anything because it’s missing a _____

A

listener

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q
const EventEmitter = require('events');
const emitter = new EventEmitter();

emitter.addListener is the same as emitter._____

A

emmiter.on

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q
const EventEmitter = require('events');
const emitter = new EventEmitter();

emitter.________ is the same as emitter.on

A

addListener

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

the emitter.on(); takes two parameters

A

eventName | The name of the event.

listener The callback function

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

When creating multiple messages in the code below its best to encapsulate them in a ______

emitter.emit(‘messageLogged’);

A

object

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

What is an event?

emitter.on(‘messageLogged’, function(){
console.log(‘Listening’);
})

emitter.emit(‘messageLogged’);

A

emitter.emit(‘messageLogged’);

39
Q

What is an listener?

emitter.on(‘messageLogged’, function(){
console.log(‘Listening’);
})

emitter.emit(‘messageLogged’);

A

emitter.on(‘messageLogged’, function(){
console.log(‘Listening’);
})

40
Q

when a function is inside a class syntax we do not need the ____ keyword

A

function

41
Q

To use the HTTP server and client one must require___

A

(‘http’)

42
Q

Write a HTTP module, store in a variable

A

const http = require(‘http’)

43
Q

NPM stands for?

A

Node Package Manager

44
Q

how to get the version of a program?

A

-v

45
Q

before adding node packages you need to create ______ file

A

package.json

46
Q

to create a .json file we use _____ in the terminal

A

npm init

47
Q

to create a .json file with default parameters we add ____ to the termina

A

npm init –yes

48
Q

the keyword to install a node package in terminal is ________ and the shortcut is ____

A

install

i

49
Q

const _ =

import the underscore npm package

A

const _ = require (“underscore”);

50
Q
What are the 3 levels of node Package Mangers
when it views code like: const _ = require ("underscore");
A
  1. core moduel
  2. file or folder
  3. node_modules
51
Q

const _ = require (“underscore”);

Js knows underscore is not a file or folder as it’s missig the ______

A

./

dot slash before name

52
Q

to reinstall NPM dependencies in a new file type __

A

npm i

in terminal

53
Q

to list all files and folders from a project we first create a
_____ folder

then create a _______ folder

in the file write___

A

git init

.gitignore folder

node_modules/

54
Q

Semantic Versioning
4.5.33

what is 4 called?
what is 5 called?
what is 33 called?

A

major version
minor version (new features that dont break API)
patch (bug fixes)

55
Q

an example of Semantic Versioning?

A

4.5.33

56
Q

^4.14.5 SemVer is equal to

A

4.x.5

57
Q

if you want a NPM package of the same version you remove the _____ or _____

A

~

58
Q

to see all NPM packages and versions type in terminal _______

A

NPM list

59
Q

the NPM LIST command will give a large tree. What command to just list our packages?

A

npm list –depth=0

60
Q

to get the details of an NPM package type

A

npm view “package name”

61
Q

to get the details of an NPM package type and ONLY versions

A

npm view “package name” “versions”

62
Q

type what in terminal to install mongoose version 2.4.2

A

npm i mongoose@2.4.2

63
Q

to check to see what NPM package are outdated tyep??

A

npm outdated

64
Q

to update all NPM packages type __?

A

npm update

65
Q

the keyword for removing a NPM package is ______ and the shortcut is

A

uninstall

un

66
Q

to install a NPM globally like NPM itself use the flag

A

-g

67
Q

uninstall an NPM global package

A

npm un -g “package”

68
Q

What does REST stand for

A

REpresentational State Transfer

69
Q

REST does 4 things called CRUD. What is CRUD?

A

Create
Read
Update
Delete

70
Q

what are the 4 main HTTP Methods?

A

Get
Post
Put
Delete

71
Q

the NPM that will allow us not to restart the stop the terminal process in a port

A

nodemon

72
Q

another name for an environment variable

A

port

73
Q

what object do we use to create a port

A

Process

74
Q

we want to change the PORT in the terminal, what do we write?

A

export PORT=

75
Q

in the code editor how do we reassign a port?

A

const port = process.env.PORT || 3000;

76
Q

_______ is a simple minimalistic and lightweight framework for building web servers

A

Express

77
Q

Using Express what are the two lines of code for a server?

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

the status code of an object not found is

A

404

79
Q

a Bad request is number

A

400

80
Q
function sayHello(){
    console.log("hello!!!!!");
}

// in node the above did not print to the console, why?

A

did not call the function

sayHello();

81
Q
function sayHello(na){
    console.log(na);
}

sayHello(window);// returns

A

ReferenceError: window is not defined

82
Q
var message = '';
console.log(global.message);

Variables and functions in node are scope to their ____

A

file

83
Q

modules in JS are ______

A

objects

84
Q

REST and HTTP are not same

true/false

A

true

85
Q

________ is the protocol that allows for sending documents back and forth on the web

A

HTTP

86
Q

the function that is used in node and modules as a IFE is called

A

Module Wrapper Function

87
Q

a single thread application is async or sync

A

sync

88
Q

What function must go first?

emitter. emit(); //raise an event?
emitter. on(); //listener?

A

emitter.on();

89
Q

API stands for?

A

Application Program Interface

90
Q

what is middleware

A

functions have access to the request and response object.

91
Q

with NPM to install a dev dependency use the flag

A

-D

92
Q

middleware functions take 3 parameters

A

req, res, next

next always last

93
Q
const logger = (req, res, next) => {
//code
}

// what code here to start logger?

A

app.use(logger);