Node.js Flashcards

1
Q

What is Node.js?

A

Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser

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

Is Node.js a framework or language?

A

Neither. It is a JavaScript runtime built on Chrome’s V8 JavaScript engine. It extends the power of handling file and network I/O with a preference for asynchronous patterns after including everything that is Javascript.

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

What is the event/task queue?

A

Task queue is a data structure that holds callback functions to be executed. A task which is queued first is processed first (first in, first out).

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

What is a tick?

A

Every time the event loop takes a full trip

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

What does process.nextTick() do?

A

When we pass a function to process.nextTick(), we instruct the engine to invoke this function at the end of the current operation, before the next event loop tick start (vs. at the end of the next tick)

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

What is an API?

A

Application Programming Interface. APIs define how a web server responds to requests. The API determines what kinds of functions the server should support and how those functions should be used. API are a software intermediary that allows two applications to talk to each other

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

What is process in node?

A

The process object provides information about, and control over, the current Node.js process.

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

Describe Node.js. List benefits and drawbacks.

A

Node.js is a JavaScript runtime built on Chrome’s v8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O (in-out) model that makes it lightweight and efficient. Node.js’ package ecosystem, npm, is the largest ecosystem of open source libraries in the world. A runtime is something that provides custom functionality so various tools and libraries specific to the environment (it is not a programming language).

Benefits:

  • It re-uses Javascript- meaning a front-end Javascript developer can also build an entire server themselves
  • It’s easily extendable- numerous plugins exist to expand on the capabilities of Node
  • Fast-implementation- which allows for the creation of an entire working server with only a few lines of code
  • Single-threaded asynchronous model- meaning it can handle multiple requests simultaneously and not get bottlenecked
  • It is non-blocking because Node uses other threads in C++ to manage your events

Drawbacks:
-Node is not particularly good at things like video processing or machine learning. These are blocking, processor heavy operations

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

Update to the callback queue: TaskQueue and JobQueue. What is in each and what takes priority?

A

Macrotasks are called Tasks. Examples of tasks are setTimeout, setInterval, seImmediate, I/O tasks
Microtasks are calls Jobs. Examples of jobs are Promises, process.nextTick
The JobQueue gets higher precedence than TaskQueue

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