NodeJs Flashcards
what’s compiled binary file in nodejs, how to do that?
- 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
Event loop in Nodejs
- 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
5 phases of event loops
- Timers
- I/O logic
- Polling
- Check
- Close
What’s the Microtasks ?
immidate tasks
These are executed after each phase of the event loop. This is where promises are executed.
- process.nextTick()
- promise.then()
setTimeout vs. setImmediate
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
Helmet is a Node.js?
It helps protect web applications from a variety of common security vulnerabilities, such as cross-site scripting (XSS), clickjacking, and more.
Morgan Middleware in nodejs ?
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.
Why using classes for defining DTO instead of interfaces in NestJs?
- 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
Decorator vs decorator factory in typescript
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.
use cases of node-http-proxy
HTTP proxy is like a middleman
Loadbalancing
API gateway
Improving security
Access control
caching content to speed up access