NodeJs Flashcards

1
Q

what’s compiled binary file in nodejs, how to do that?

A
  • create a standalone, self-contained binary from your JavaScript or TypeScript source code
  • without needing to install npm/Deno or dependencies
  • achieve faster startup time

deno compile
nexe or pkg do for Node

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

Event loop in Nodejs

A
  • is used by NodeJs for async actions
  • it uses threads within libuv
  • for io-bound operations
  • event loop gets initiated inside the main thread
  • root code executed before event loop
  • each cycle of event loop is called a Tick
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

5 phases of event loops

A
  1. Timers
  2. I/O logic
  3. Polling
  4. Check
  5. Close
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s the Microtasks ?

A

immidate tasks
These are executed after each phase of the event loop. This is where promises are executed.

  • process.nextTick()
  • promise.then()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

setTimeout vs. setImmediate

A

The “setTimeout” function in Node.js is commonly used to schedule functions to be executed after a certain amount of time.

“setImmediate” functions are executed before any pending “setTimeout” callbacks, I/O callbacks

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

Helmet is a Node.js?

A

It helps protect web applications from a variety of common security vulnerabilities, such as cross-site scripting (XSS), clickjacking, and more.

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

Morgan Middleware in nodejs ?

A

Morgan is a popular logging middleware for Node.js applications. It is used to log HTTP requests and responses in a structured format, making it easier to monitor and debug web server activity.

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

Why using classes for defining DTO instead of interfaces in NestJs?

A
  • interfaces are a part of TS and are not preserved post-compilation
  • classes allow to do more
  • NestJs cannot refer to interfaces in run-time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Decorator vs decorator factory in typescript

A

In TypeScript, decorators are a way to add metadata to classes, methods, or properties.

  • Decorator: Applied directly to the target without parameters.
  • Decorator Factory: Used to create decorators with parameters or to customize the behavior of the decorator.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly