COSC 209 qa 1
COSC 209 qa 1
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"?