NodeJS Flashcards

1
Q

What is NodeJS?

A

NodeJS is a Javascript runtime that works for backend programming

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

NodeJS extends from an engine, what engine?

A

V8 Google engine, used to mainly in google chrome and NodeJs

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

Which language is V8 written in?

A

written in C++, to support Javascript.

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

How to execute Node from Cmd?

A

typing node

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

requiring a library that deals with file i/o

A

const fs = require(‘fs’)

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

creating a file synchronously with some content

A

fs.writeFileSync(‘filename.txt’, ‘filecontent’);

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

One example of development that is not associated with developing for server-side with NodeJS

A

Dealing with local files to process Building of production versions, ReactJs uses node indirectly for that, creating utility scripts in general.

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

What are the two ways of executing Node code?

A

by executing files (node (filename)) or REPL:

Read, Evaluate, Print, Loop, which is a way of executing code on the go in the command line, good playground.

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

Module to help with path concatenations

A

path, path.resolve(path1, path2)

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

The NodeJS event loop consists of 5 basic processes, the first step is

A
  1. Execution of timer functions (setTimer, setInterval, etc);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The NodeJS event loop consists of 5 basic processes, the second step is

A
  1. Execute pending (non-timer) callbacks from previous loops, such as I/O related callbacks and other events
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The NodeJS event loop consists of 5 basic processes, the third step is

A
  1. Fetch new (non-timer) Event callbacks such as new connections and try to execute them right away, Or defer them to be executed in the next loop (2nd step)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The NodeJS event loop consists of 5 basic processes, the forth step is

A
  1. execute setImediate() callbacks, these are callbacks that execute always in the same loop, but always after all previous steps
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The NodeJS event loop consists of 5 basic processes, the last step is

A
  1. Execute all ‘close’ event callbacks
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What can happen when a long operation has to be executed by NodeJs?

A

It transfer the operation to the poll workers, which is carried with the work of deferring the process to another thread, the workers make sure this process happens automatically.

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

How to serve a file with the absolute path and the .html file to a user?

A
const path = require('path');
res.sendFile(path.join(\_\_dirname, '/view/page.html');
17
Q

What does express.use(‘/admin’, adminRouter); does?

A

appends the path ‘/admin’ to all routes inside adminRouter.

18
Q

Difference between path.resolve() vs path.join()

A

path. resolve is absolute, gets the root directory all the way from C:\
path. join starts with ‘./’, is relative, plus it converts the path in a way that works for both linux and windows.

19
Q

consider: path.join(__dirname, ‘..’, ‘views’, ‘index.html’);

why is using ‘..’ instead of ‘../’ useful?

A

Because it goes up 1 directory level while preserving compatibility between different OS’s paths structure

20
Q

what does path.dirname(string dir) returns?

A

returns the current already formated path, good for modularization and helper functions.

21
Q

how to retrieve the application main entry point defined in package.json with the ‘process’ global var?

A

proccess.mainModule.filename

22
Q

express().set() and express().get() does

A

sets a global variable that express may or may not understand, like: app.set(‘var_name’, ‘value’)

express.get(‘var_name’) will return it globally.

23
Q

setting a templating engine with express

A

express().set(‘view engine’, (engine));
‘view engine’ is a reserved express global configuration option.

(engine) configures one of the templating engines that have built-in compatibility with express, such as pug, ejs.
(optional) telling express where is the root folder of the views:

express().set(‘views’, ‘(folder_path)’) // Default path location is ‘views’.

24
Q

method to build on-the-fly and send to the user a dynamically outputted html page

A

res.render();