0% found this document useful (0 votes)
2 views

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)
2 views

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
You are on page 1/ 6

1. What is Node.js? Where can you use it?

Node.js 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 Node.js?
Node.js 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 Node.js work?
Node.js 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 Node.js single-threaded?
Node.js 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 Node.js is single-threaded, then how does it handle concurrency?
Node.js uses an event loop and asynchronous callbacks to handle multiple tasks without
blocking the main thread.
6. Explain briefly callback in Node.js
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 Node.js 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 Node.js projects.
12. What are the modules in Node.js?
Modules are reusable JavaScript code libraries for specific functionalities, like HTTP, FS
(file system), and path handling.
13. What is the purpose of the module.exports?
module.exports allows exporting functions, objects, or values from a module to be used in
other files.
14. Why is Node.js preferred over other backend technologies like Java and PHP?
Node.js 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 Node.js?
Angular is a front-end framework for building user interfaces, while Node.js is a runtime
for executing JavaScript on the server.
16. Which database is more popularly used with Node.js? Why?
MongoDB is popular with Node.js because both use JavaScript/JSON, making data
handling more seamless across the stack.
17. What are some of the most commonly used libraries in Node.js?
Common libraries include Express (web framework), Mongoose (MongoDB handling),
Lodash (utility functions), and Axios (HTTP requests).
18. What are the pros and cons of Node.js?
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 Node.js?
The event loop is a mechanism that allows Node.js to perform non-blocking I/O by
processing asynchronous callbacks in a single thread.
22. Differentiate between process.nextTick() and setImmediate()
process.nextTick() 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 Node.js?
EventEmitter is a class in Node.js that allows objects to emit events and register
listeners for those events.
24. What are the two types of API functions in Node.js?
Asynchronous (non-blocking) and synchronous (blocking) functions.
25. What is the package.json file?
It’s a configuration file that stores project metadata, dependencies, scripts, and
configuration settings.
26. How would you use a URL module in Node.js?
Use require('url') to parse, format, and resolve URLs.
27. What is the Express.js package?
Express.js is a web application framework for building APIs and web apps in Node.js.
28. How do you create a simple Express.js application?
Import Express, create an app instance, define routes, and use app.listen() to start the
server.
29. What are streams in Node.js?
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 Node.js that returns "Hello World"?

const http = require('http');


http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World');
}).listen(3000);

32. Explain asynchronous and non-blocking APIs in Node.js.


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 Node.js?
Use callbacks, Promises, or async/await.
34. What is a callback function in Node.js?
A callback function is a function passed as an argument to execute once an
asynchronous operation is complete.
35. What is REPL in Node.js?
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 Node.js?
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 Node.js?
Buffer stores raw binary data and allows manipulation of binary streams.
40. What is piping in Node.js?
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 Node.js?
Use fs.open() from the fs module:
const fs = require('fs');
fs.open('file.txt', 'r', (err, fd) => {
if (err) throw err;
console.log('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 Node.js?
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 Node.js?
It’s a strategy for testing APIs, with more unit tests than integration or end-to-end tests.
46. For Node.js, why does Google use the V8 engine?
V8 compiles JavaScript to machine code, making Node.js fast and efficient.
47. Describe Node.js exit code.
An exit code indicates the completion status of a Node.js process; 0 is successful, non-
zero codes indicate errors.
48. Explain the concept of middleware in Node.js.
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 Node.js?
Use the MongoDB or Mongoose library to connect using MongoClient.connect() or
mongoose.connect().
51. What is the purpose of NODE_ENV?
NODE_ENV specifies the environment (development, production) for configuration.
52. List the various Node.js timing features.
setTimeout(), setInterval(), setImmediate(), process.nextTick().
53. What is WASI, and why is it being introduced?
WebAssembly System Interface (WASI) allows Node.js 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 Node.js?
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 Node.js?
To handle multiple concurrent connections efficiently without blocking.
58. What is the difference between Node.js and AJAX?
Node.js runs JavaScript on the server, while AJAX fetches data asynchronously on the
client.
59. What is the advantage of using Node.js?
Fast, scalable, single language across stack, and has a large ecosystem of libraries.
60. Does Node.js run on Windows?
Yes, Node.js is cross-platform and runs on Windows.
61. Can you access DOM in Node.js?
No, Node.js doesn’t have a DOM as it runs on the server.
62. Why is Node.js 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 Node.js?
Single-thread limitations, not ideal for CPU-heavy tasks, and potential security risks in
dependencies.
64. What is "non-blocking" in Node.js?
Non-blocking means tasks can start without waiting for others to finish, enabling
concurrency.
65. How does Node.js overcome the problem of blocking I/O operations?
Node.js uses asynchronous, event-driven programming with an event loop.
66. How can we use async/await in Node.js?
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 Node.js.
Stubs replace functions for testing purposes, allowing controlled outputs.
69. What is the framework that is used majorly in Node.js today?
Express.js is the most widely used framework.
70. What are the security implementations in Node.js?
Security includes validation, authentication, rate limiting, helmet middleware, and
sanitization.
71. What is Libuv?
Libuv is a library that handles Node.js’s asynchronous I/O operations and event loop.
72. What are global objects in Node.js?
Global objects are available anywhere in Node.js, like global, process, __dirname, and
__filename.
73. Why is assert used in Node.js?
Assert is used for simple testing by verifying expressions and throwing errors for failed
conditions.
74. Why is Express.js used?
Express is used for simplifying server creation, routing, middleware management, and
API development.
75. What is the use of the connect module in Node.js?
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 Node.js?
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 Node.js handle child threads?
Node.js uses child processes for multi-threading via child_process module, not threads.
81. What is an EventEmitter in Node.js?
An EventEmitter allows handling events by emitting and listening to them.
82. How to enhance Node.js performance through clustering?
Use cluster module to create multiple instances of Node.js for handling concurrent
requests.
83. What is a thread pool, and which library handles it in Node.js?
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 console.time() and console.timeEnd() to track operation times.
86. How to measure the performance of async operations?
Use performance.now(), console.time(), or profiling tools like Node’s --inspect.
87. What are the types of streams available in Node.js?
Readable, Writable, Duplex, and Transform streams.
88. What is meant by tracking in Node.js?
Tracking helps in monitoring performance and debugging code.
89. Where is package.json used in Node.js?
It’s used to manage project dependencies, scripts, and configurations.
90. What is the difference between readFile and createReadStream in Node.js?
readFile reads the file into memory entirely; createReadStream reads the file in chunks.
91. What is the use of the crypto module in Node.js?
The crypto module provides cryptographic functionality, like hashing and encryption.
92. What is Passport in Node.js?
Passport is an authentication middleware for managing user authentication in Node.js
applications.

You might also like