Basic Questions Flashcards

(32 cards)

1
Q

What is Node.js?

A

Node.js is a runtime environment for executing JavaScript outside the browser, particularly on web servers. It is built on Chrome’s V8 engine and is used to build scalable, event-driven server applications.

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

What is a runtime environment?

A

A runtime environment is the platform or infrastructure in which a program or script is executed. In the context of Node.js, it refers to the V8 engine, which allows you to run JavaScript outside of the browser

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

What is the difference between req.params and req.query?

A

req.params retrieves parameters embedded within the route’s path. req.query retrieves query string values appended to the URL. req.params is used for route matching, while req.query is used for filtering, pagination, and dynamic queries.

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

What is body-parser

A

body-parser is a middleware for Express.js that parses incoming request bodies before handlers. It converts raw incoming payloads, such as strings, into JSON accessible on req.body.

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

What security mechanisms are available in Node.js?

A

Node.js security mechanisms include using helmet middleware to set HTTP headers for protection against common vulnerabilities, input validation and sanitization, enabling HTTPS, handling authentication and authorization, using environment variables for secrets, and keeping dependencies updated.

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

What is REST?

A

Representational State Transfer (REST) is an architectural style for designing server interfaces. It organizes data and operations as resources accessible via stateless protocols such as HTTP.

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

What are the characteristics of REST?

A

statelessness (server does not retain client state between requests), , resource-based architecture (each piece of data is a resource with a URI), client-server architecture (clients and servers are separate), and a uniform interface (standard methods and representations for interacting with resources).

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

What does statelessness mean in REST APIs?

A

Statelessness means the server handles each request independently of other requests, and does not remember the client’s data between requests.

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

What is JWT and how does it enable stateless authorization?

A

JWT (JSON Web Token) allows for stateless authorization, meaning tokens contain all the info needed for authentication and are verified by the server’s secret signature. The server does not need to store session state, only verify the token.

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

How is JWT different from traditional stateful sessions?

A

In stateful sessions, the server keeps track of client data, maintaining session state across requests. With JWT, every request is authenticated independently using the token, allowing the server to be stateless and scalable.

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

What is a process in computer science?

A

A process is a running program with its own memory space and resources. In analogy, it’s like a restaurant where tasks are handled independently.

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

What is a thread?

A

A thread is a unit of execution within a process. A process can have multiple threads, analogous to waiters serving different tables within a restaurant.

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

How many threads does JavaScript use in Node.js?

A

JavaScript itself uses a single thread for executing code in Node.js, which means only one operation executes at a time on the main thread.

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

What is the call stack in JavaScript?

A

The call stack is a data structure that keeps track of function invocations. When a function is called, it is pushed onto the stack, and when it completes, it is popped off.

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

What happens if a task takes too long to complete in single-threaded JavaScript?

A

If a task takes too long on the single JavaScript thread, it blocks further execution—no other code can run until the blocking task finishes.

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

How does Node.js avoid blocking operations?

A

Node.js uses an event-driven, non-blocking I/O model. When an operation requires I/O (like database reads), it delegates the task to background worker threads using libuv and the event loop, allowing the main thread to remain responsive.

17
Q

What does the event loop do in Node.js?

A

The event loop continuously checks the call stack and message queue, executing callbacks when tasks complete, enabling asynchronous operations without blocking the single thread.

18
Q

How does Node.js handle heavy I/O tasks?

A

Heavy I/O tasks are offloaded to background worker threads managed by libuv. Upon completion, results are returned via the event demultiplexer, and the event loop dispatches the callback for further processing.

19
Q

Give an analogy for Node.js’s asynchronous task handling.

A

Node.js is like a restaurant manager (event demultiplexer) who receives multiple orders at once and notifies waiters (callbacks) when specific food (data) is ready, so no customer (task) is left waiting for too long.

20
Q

What is synchronous programming?

A

Synchronous programming is thread-blocking; each operation waits for the previous one to finish before starting.

21
Q

What is asynchronous programming?

A

Asynchronous programming allows certain operations to run in the background, enabling other code to execute without waiting for them to finish.

22
Q

What is a Promise in JavaScript?

A

A Promise is an object that represents the eventual completion (or failure) of an asynchronous operation and its resulting value.

23
Q

What is the benefit of asynchronous programming in JavaScript?

A

It enables non-blocking operations, allowing applications to be responsive and handle multiple tasks efficiently, especially for I/O or network-bound tasks.

24
Q

How do callbacks relate to asynchronous programming?

A

Callbacks are functions passed as arguments to other functions, executed when an asynchronous operation completes, enabling further logic without blocking the main thread.

25
How does async/await improve asynchronous programming?
Async/await syntax makes asynchronous code look and behave like synchronous code, improving readability and simplifying error handling by using try/catch blocks.
26
What is the package.json file in Node.js?
The package.json file is a manifest file in JSON format that stores essential metadata and configuration details about the project, such as its name, version, dependencies, scripts, author information, and more.
27
What is hoisting in JavaScript?
Hoisting is JavaScript's behavior of moving declarations (variables and functions) to the top of their containing scope during compilation. This allows a variable to be accessible before it is declared'
28
What is 'var' in JavaScript?
'var' is a keyword used to declare a variable, with function-level scope. Variables declared with 'var' can be re-declared and re-assigned, and are hoisted to the top of their enclosing function or global scope.
29
What is 'let' in JavaScript?
'let' declares a block-scoped variable. 'let' allows variable re-assignment but not re-declaration within the same scope. It’s not hoisted in the same way as 'var', improving safety in block-level code.
30
What is 'const' in JavaScript?
'const' declares a block-scoped variable whose value cannot be re-assigned after its initial assignment. 'const' must be initialized when declared and cannot be re-declared or re-assigned, but its object properties can still be modified.
31
What are the main parts of a URL?
The main parts of a URL are: 1) Scheme or protocol (e.g., http, https) 2) Host or domain (e.g., www.example.com) 3) Port (optional, e.g., :3000) 4) Path (e.g., /users/profile) 5) Query string (optional, starts with '?', e.g., ?id=123) 6) Fragment or hash (optional, starts with '#', e.g., #section1).
32
What is a subdomain?
A subdomain is a prefix added to a domain name to organise or subdivide different sections of a website.