0% found this document useful (0 votes)
30 views6 pages

COSC 209 Qa 1

Node.js is a server-side runtime environment for executing JavaScript, ideal for backend development, APIs, and real-time applications due to its fast, scalable, and non-blocking I/O model. It uses an event-driven architecture and the V8 engine, allowing it to handle multiple connections efficiently. Key features include the use of NPM for package management, Express.js for web applications, and various asynchronous programming techniques like callbacks and promises.

Uploaded by

msowunmi2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views6 pages

COSC 209 Qa 1

Node.js is a server-side runtime environment for executing JavaScript, ideal for backend development, APIs, and real-time applications due to its fast, scalable, and non-blocking I/O model. It uses an event-driven architecture and the V8 engine, allowing it to handle multiple connections efficiently. Key features include the use of NPM for package management, Express.js for web applications, and various asynchronous programming techniques like callbacks and promises.

Uploaded by

msowunmi2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1. What is [Link]? Where can you use it?

[Link] is a runtime environment for executing JavaScript on the server side. You can
use it for backend web development, APIs, microservices, real-time applications (like
chat), and more.
2. Why use [Link]?
[Link] is fast, scalable, and uses JavaScript across the stack, making it great for real-
time applications and handling many connections at once with low latency.
3. How does [Link] work?
[Link] uses the V8 JavaScript engine to execute code. It operates on a single thread
and uses an event-driven, non-blocking I/O model, allowing it to handle many tasks
asynchronously.
4. Why is [Link] single-threaded?
[Link] is single-threaded to simplify concurrency and make it more efficient in handling
asynchronous tasks, reducing the overhead that comes with multi-threaded contexts.
5. If [Link] is single-threaded, then how does it handle concurrency?
[Link] uses an event loop and asynchronous callbacks to handle multiple tasks without
blocking the main thread.
6. Explain briefly callback in [Link]
A callback is a function passed as an argument to another function, allowing
asynchronous operations to execute code once the operation completes.
7. What are the advantages of using promises instead of callbacks?
Promises make code cleaner, handle errors better, and simplify chaining asynchronous
operations without deeply nested callbacks (callback hell).
8. How would you define the term I/O?
I/O (Input/Output) refers to reading or writing operations, such as accessing databases,
files, or APIs.
9. How is [Link] most frequently used?
It’s used for building servers, REST APIs, real-time applications (like chat and gaming),
and microservices.
10. Explain briefly the difference between frontend and backend development
Frontend is the client side, focused on user interface and experience. Backend is the
server side, handling data storage, processing, and business logic.
11. What is NPM?
NPM (Node Package Manager) is a tool for managing JavaScript packages and libraries,
used to install, update, and manage dependencies in [Link] projects.
12. What are the modules in [Link]?
Modules are reusable JavaScript code libraries for specific functionalities, like HTTP, FS
(file system), and path handling.
13. What is the purpose of the [Link]?
[Link] allows exporting functions, objects, or values from a module to be used in
other files.
14. Why is [Link] preferred over other backend technologies like Java and PHP?
[Link] is lightweight, handles asynchronous tasks well, has a vast package ecosystem,
and allows JavaScript to be used across the stack.
15. What is the difference between Angular and [Link]?
Angular is a front-end framework for building user interfaces, while [Link] is a runtime
for executing JavaScript on the server.
16. Which database is more popularly used with [Link]? Why?
MongoDB is popular with [Link] because both use JavaScript/JSON, making data
handling more seamless across the stack.
17. What are some of the most commonly used libraries in [Link]?
Common libraries include Express (web framework), Mongoose (MongoDB handling),
Lodash (utility functions), and Axios (HTTP requests).
18. What are the pros and cons of [Link]?
Pros: Fast, scalable, extensive package ecosystem, and uses JavaScript throughout.
Cons: Single-threaded (not ideal for CPU-heavy tasks), callback hell, and potential
security issues if dependencies aren’t managed well.
19. What is the command used to import external libraries?
require('library-name');
20. What does event-driven programming mean?
In event-driven programming, actions are triggered by events (like clicks or data arrival),
allowing asynchronous handling of these events.
21. What is an event loop in [Link]?
The event loop is a mechanism that allows [Link] to perform non-blocking I/O by
processing asynchronous callbacks in a single thread.
22. Differentiate between [Link]() and setImmediate()
[Link]() executes immediately after the current operation completes, while
setImmediate() schedules code to execute in the next event loop cycle.
23. What is an EventEmitter in [Link]?
EventEmitter is a class in [Link] that allows objects to emit events and register
listeners for those events.
24. What are the two types of API functions in [Link]?
Asynchronous (non-blocking) and synchronous (blocking) functions.
25. What is the [Link] file?
It’s a configuration file that stores project metadata, dependencies, scripts, and
configuration settings.
26. How would you use a URL module in [Link]?
Use require('url') to parse, format, and resolve URLs.
27. What is the [Link] package?
[Link] is a web application framework for building APIs and web apps in [Link].
28. How do you create a simple [Link] application?
Import Express, create an app instance, define routes, and use [Link]() to start the
server.
29. What are streams in [Link]?
Streams are data-handling objects that let you read or write data continuously.
30. How do you install, update, and delete a dependency?
Use npm install package, npm update package, and npm uninstall package.
31. How do you create a simple server in [Link] that returns "Hello World"?

const http = require('http');


[Link]((req, res) => {
[Link](200, {'Content-Type': 'text/plain'});
[Link]('Hello World');
}).listen(3000);

32. Explain asynchronous and non-blocking APIs in [Link].


Asynchronous APIs execute tasks in the background, while non-blocking APIs don’t wait
for tasks to complete before continuing.
33. How do we implement async in [Link]?
Use callbacks, Promises, or async/await.
34. What is a callback function in [Link]?
A callback function is a function passed as an argument to execute once an
asynchronous operation is complete.
35. What is REPL in [Link]?
REPL (Read-Eval-Print Loop) is an interactive shell for executing JavaScript commands.
36. What is a control flow function?
A control flow function manages the execution order of asynchronous functions.
37. How does control flow manage function calls?
It controls execution order, error handling, and data passing among asynchronous tasks.
38. What is the difference between fork() and spawn() methods in [Link]?
fork() creates a new process with its own V8 instance; spawn() launches a new process to
run a command.
39. What is the buffer class in [Link]?
Buffer stores raw binary data and allows manipulation of binary streams.
40. What is piping in [Link]?
Piping passes data from one stream directly to another, like reading a file and writing it
to another.
41. What are some flags used in file read/write operations?
Flags include 'r' (read), 'w' (write), 'a' (append), and 'r+' (read and write).
42. How do you open a file in [Link]?
Use [Link]() from the fs module:
const fs = require('fs');
[Link]('[Link]', 'r', (err, fd) => {
if (err) throw err;
[Link]('File opened');
});

'r' opens the file in read mode.


43. What is callback hell?
Callback hell occurs when multiple nested callbacks make code hard to read and
maintain.
44. What is the reactor pattern in [Link]?
It’s an event-processing pattern used to handle asynchronous I/O, core to Node’s non-
blocking model.
45. What is a test pyramid in [Link]?
It’s a strategy for testing APIs, with more unit tests than integration or end-to-end tests.
46. For [Link], why does Google use the V8 engine?
V8 compiles JavaScript to machine code, making [Link] fast and efficient.
47. Describe [Link] exit code.
An exit code indicates the completion status of a [Link] process; 0 is successful, non-
zero codes indicate errors.
48. Explain the concept of middleware in [Link].
Middleware functions are executed sequentially during request-response cycles,
processing requests before sending responses.
49. What are the different types of HTTP requests?
GET, POST, PUT, DELETE, PATCH, and OPTIONS.
50. How would you connect a MongoDB database to [Link]?
Use the MongoDB or Mongoose library to connect using [Link]() or
[Link]().
51. What is the purpose of NODE_ENV?
NODE_ENV specifies the environment (development, production) for configuration.
52. List the various [Link] timing features.
setTimeout(), setInterval(), setImmediate(), [Link]().
53. What is WASI, and why is it being introduced?
WebAssembly System Interface (WASI) allows [Link] to run WebAssembly modules
securely and efficiently.
54. What is a first-class function in JavaScript?
First-class functions can be assigned to variables, passed as arguments, and returned
from other functions.
55. What are the input arguments for an asynchronous queue?
They are typically the task function, callback, and concurrency limit.
56. Are there any disadvantages to using [Link]?
Not ideal for CPU-intensive tasks, single-threaded limitations, and callback hell.
57. What is the primary reason for using the event-based model in [Link]?
To handle multiple concurrent connections efficiently without blocking.
58. What is the difference between [Link] and AJAX?
[Link] runs JavaScript on the server, while AJAX fetches data asynchronously on the
client.
59. What is the advantage of using [Link]?
Fast, scalable, single language across stack, and has a large ecosystem of libraries.
60. Does [Link] run on Windows?
Yes, [Link] is cross-platform and runs on Windows.
61. Can you access DOM in [Link]?
No, [Link] doesn’t have a DOM as it runs on the server.
62. Why is [Link] quickly gaining attention from Java programmers?
It’s lightweight, has fast I/O, uses JavaScript, and is well-suited for real-time apps.
63. What are the challenges with [Link]?
Single-thread limitations, not ideal for CPU-heavy tasks, and potential security risks in
dependencies.
64. What is "non-blocking" in [Link]?
Non-blocking means tasks can start without waiting for others to finish, enabling
concurrency.
65. How does [Link] overcome the problem of blocking I/O operations?
[Link] uses asynchronous, event-driven programming with an event loop.
66. How can we use async/await in [Link]?
Declare a function as async and use await to pause execution until a Promise resolves.
67. Why should you separate the Express app and server?
Separation improves modularity, testability, and reusability of the app logic.
68. Explain the concept of stub in [Link].
Stubs replace functions for testing purposes, allowing controlled outputs.
69. What is the framework that is used majorly in [Link] today?
[Link] is the most widely used framework.
70. What are the security implementations in [Link]?
Security includes validation, authentication, rate limiting, helmet middleware, and
sanitization.
71. What is Libuv?
Libuv is a library that handles [Link]’s asynchronous I/O operations and event loop.
72. What are global objects in [Link]?
Global objects are available anywhere in [Link], like global, process, __dirname, and
__filename.
73. Why is assert used in [Link]?
Assert is used for simple testing by verifying expressions and throwing errors for failed
conditions.
74. Why is [Link] used?
Express is used for simplifying server creation, routing, middleware management, and
API development.
75. What is the use of the connect module in [Link]?
Connect is a middleware framework that simplifies building applications with
middleware.
76. What is the difference between "frontend" and "backend" development?
Frontend is the client interface; backend handles data processing, storage, and server
logic.
77. What are LTS releases of [Link]?
LTS (Long Term Support) releases are stable versions with longer support for security
and performance updates.
78. What do you understand about ESLint?
ESLint is a tool for identifying and fixing JavaScript code quality issues.
79. Define the concept of the test pyramid. Please briefly explain the process of
implementing it in terms of HTTP APIs.
The test pyramid emphasizes more unit tests, fewer integration tests, and the fewest
end-to-end tests, balancing speed and coverage.
80. How does [Link] handle child threads?
[Link] uses child processes for multi-threading via child_process module, not threads.
81. What is an EventEmitter in [Link]?
An EventEmitter allows handling events by emitting and listening to them.
82. How to enhance [Link] performance through clustering?
Use cluster module to create multiple instances of [Link] for handling concurrent
requests.
83. What is a thread pool, and which library handles it in [Link]?
A thread pool manages multiple worker threads for async tasks, handled by Libuv.
84. How are worker threads different from clusters?
Worker threads share memory in one process, while clusters spawn separate processes
with separate memory.
85. How to measure the duration of async operations?
Use [Link]() and [Link]() to track operation times.
86. How to measure the performance of async operations?
Use [Link](), [Link](), or profiling tools like Node’s --inspect.
87. What are the types of streams available in [Link]?
Readable, Writable, Duplex, and Transform streams.
88. What is meant by tracking in [Link]?
Tracking helps in monitoring performance and debugging code.
89. Where is [Link] used in [Link]?
It’s used to manage project dependencies, scripts, and configurations.
90. What is the difference between readFile and createReadStream in [Link]?
readFile reads the file into memory entirely; createReadStream reads the file in chunks.
91. What is the use of the crypto module in [Link]?
The crypto module provides cryptographic functionality, like hashing and encryption.
92. What is Passport in [Link]?
Passport is an authentication middleware for managing user authentication in [Link]
applications.

You might also like