Node.JS Flashcards

CodeWithMosh (93 cards)

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
Asynchronous is associated with blocking or non-blocking
non-blocking
26
Synchronous is associated with blocking or non-blocking
blocking
27
const fs = require('fs'); const files = fs.readdirSync(____)
./ | dot slash
28
all async methods take a_____ as the last element
function
29
a name for a signal that something has happened
event
30
The events module name is always capilatized because its a __________
class
31
events module are? - functions - class - variables
class
32
emit means
make a noise or produce a signal
33
``` const EventEmitter = require('events'); const emitter = new EventEmitter(); emitter.emit('messageLogged'); ``` the code above won't do anything because it's missing a _____
listener
34
``` const EventEmitter = require('events'); const emitter = new EventEmitter(); ``` emitter.addListener is the same as emitter._____
emmiter.on
35
``` const EventEmitter = require('events'); const emitter = new EventEmitter(); ``` emitter.________ is the same as emitter.on
addListener
36
the emitter.on(); takes two parameters
eventName | The name of the event. listener The callback function
37
When creating multiple messages in the code below its best to encapsulate them in a ______ emitter.emit('messageLogged');
object
38
What is an event? emitter.on('messageLogged', function(){ console.log('Listening'); }) emitter.emit('messageLogged');
emitter.emit('messageLogged');
39
What is an listener? emitter.on('messageLogged', function(){ console.log('Listening'); }) emitter.emit('messageLogged');
emitter.on('messageLogged', function(){ console.log('Listening'); })
40
when a function is inside a class syntax we do not need the ____ keyword
function
41
To use the HTTP server and client one must require___
('http')
42
Write a HTTP module, store in a variable
const http = require('http')
43
NPM stands for?
Node Package Manager
44
how to get the version of a program?
-v
45
before adding node packages you need to create ______ file
package.json
46
to create a .json file we use _____ in the terminal
npm init
47
to create a .json file with default parameters we add ____ to the termina
npm init --yes
48
the keyword to install a node package in terminal is ________ and the shortcut is ____
install i
49
const _ = import the underscore npm package
const _ = require ("underscore");
50
``` What are the 3 levels of node Package Mangers when it views code like: const _ = require ("underscore"); ```
1. core moduel 2. file or folder 3. node_modules
51
const _ = require ("underscore"); Js knows underscore is not a file or folder as it's missig the ______
./ | dot slash before name
52
to reinstall NPM dependencies in a new file type __
npm i in terminal
53
to list all files and folders from a project we first create a _____ folder then create a _______ folder in the file write___
git init .gitignore folder node_modules/
54
Semantic Versioning 4.5.33 what is 4 called? what is 5 called? what is 33 called?
major version minor version (new features that dont break API) patch (bug fixes)
55
an example of Semantic Versioning?
4.5.33
56
^4.14.5 SemVer is equal to
4.x.5
57
if you want a NPM package of the same version you remove the _____ or _____
^ | ~
58
to see all NPM packages and versions type in terminal _______
NPM list
59
the NPM LIST command will give a large tree. What command to just list our packages?
npm list --depth=0
60
to get the details of an NPM package type
npm view "package name"
61
to get the details of an NPM package type and ONLY versions
npm view "package name" "versions"
62
type what in terminal to install mongoose version 2.4.2
npm i mongoose@2.4.2
63
to check to see what NPM package are outdated tyep??
npm outdated
64
to update all NPM packages type __?
npm update
65
the keyword for removing a NPM package is ______ and the shortcut is
uninstall un
66
to install a NPM globally like NPM itself use the flag
-g
67
uninstall an NPM global package
npm un -g "package"
68
What does REST stand for
REpresentational State Transfer
69
REST does 4 things called CRUD. What is CRUD?
Create Read Update Delete
70
what are the 4 main HTTP Methods?
Get Post Put Delete
71
the NPM that will allow us not to restart the stop the terminal process in a port
nodemon
72
another name for an environment variable
port
73
what object do we use to create a port
Process
74
we want to change the PORT in the terminal, what do we write?
export PORT=
75
in the code editor how do we reassign a port?
const port = process.env.PORT || 3000;
76
_______ is a simple minimalistic and lightweight framework for building web servers
Express
77
Using Express what are the two lines of code for a server?
``` const express = require('express'); const app = express(); ```
78
the status code of an object not found is
404
79
a Bad request is number
400
80
``` function sayHello(){ console.log("hello!!!!!"); } ``` // in node the above did not print to the console, why?
did not call the function sayHello();
81
``` function sayHello(na){ console.log(na); } ``` sayHello(window);// returns
ReferenceError: window is not defined
82
``` var message = ''; console.log(global.message); ``` Variables and functions in node are scope to their ____
file
83
modules in JS are ______
objects
84
REST and HTTP are not same true/false
true
85
________ is the protocol that allows for sending documents back and forth on the web
HTTP
86
the function that is used in node and modules as a IFE is called
Module Wrapper Function
87
a single thread application is async or sync
sync
88
What function must go first? emitter. emit(); //raise an event? emitter. on(); //listener?
emitter.on();
89
API stands for?
Application Program Interface
90
what is middleware
functions have access to the request and response object.
91
with NPM to install a dev dependency use the flag
-D
92
middleware functions take 3 parameters
req, res, next next always last
93
``` const logger = (req, res, next) => { //code } ``` // what code here to start logger?
app.use(logger);