


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The doccument covers both frontend languages and frameworks
Typology: Lecture notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!
1. What is Node.js? Where can you use it?
Node.js is an open-source, cross-platform JavaScript runtime environment that executes JavaScript code outside of a web browser. It is built on top of the Chrome V8 JavaScript engine and allows developers to run JavaScript on the server side. Node.js can be used to build a variety of applications, including web servers, command-line tools, and real-time event-driven systems.
2. Why use Node.js?
There are several reasons why developers might choose to use Node.js for their projects:
It allows developers to use JavaScript on the server side, which can be convenient for those who are already familiar with the language.
It is lightweight and efficient, making it well-suited for applications that require real-time communication or need to handle a large number of concurrent connections.
It has a large and active community of developers, which means that there are many open- source libraries and tools available for use.
It is well-documented and has good support for a variety of platforms and operating systems.
3. How does Node.js work?
Node.js works by using an event-driven, non-blocking I/O model that makes it lightweight and efficient. When a request is made to the Node.js server, it adds the request to an event queue and continues to process other requests. When the request is ready to be processed, a callback function is called to handle the request and generate a response. This allows the server to handle many requests concurrently without the overhead of creating a new thread for each request.
4. Why is Node.js single-threaded?
Node.js is single-threaded because it uses an event-driven, non-blocking I/O model that allows it to handle many requests concurrently without the overhead of creating new threads for each request. This makes it lightweight and efficient, but it also means that Node.js programs must be written in a way that avoids blocking the event loop.
5. If Node.js is single-threaded, then how does it handle concurrency?
Even though Node.js is single-threaded, it is able to handle concurrency by using an event loop and a callback-based architecture. When a request is made to the server, it is added to an event queue and the server continues to process other requests. When the request is ready to be processed, a callback function is called to handle the request and generate a response. This allows the server to handle many requests concurrently without creating new threads for each request.
6. Explain callback in Node.js.
A callback in Node.js is a function that is passed as an argument to another function and is executed when the second function is finished. Callbacks are used in Node.js to handle asynchronous events and to provide a way to continue processing after an asynchronous operation is complete. For example, a callback might be used to handle a database query, to read a file from the file system, or to send an HTTP request. When the asynchronous operation is complete, the callback function is called with the results of the operation as an argument.
7. What are the advantages of using promises instead of callbacks?
Promises are a more modern and powerful way to handle asynchronous events in JavaScript. They offer several advantages over traditional callback-based approaches:
They provide a cleaner and more intuitive syntax for handling asynchronous events.
They allow developers to write asynchronous code that is easier to read and understand.
They allow developers to chain together multiple asynchronous operations without the need for nested callbacks.
They provide a way to handle errors in asynchronous code more effectively.
8. How would you define the term I/O?
I/O, or input/output, refers to the process of reading and writing data to and from external devices, such as a keyboard, a mouse, a storage device, or a network connection. I/O operations are a fundamental part of computing and are used to interact with the outside world and to perform tasks such as reading and writing files, sending and receiving network requests, and interacting with users.
9. How is Node.js most frequently used?
Node.js is most frequently used to build web servers and applications that require real-time communication or the ability to handle a large number of concurrent connections. It is also often used to build command-line tools and utilities, as well as for building real-time event-driven systems.
10. Explain the difference between frontend and backend development.
Frontend development refers to the development of the client-side of a web application, including the design and functionality of the user interface. It typically involves the use of technologies such as HTML, CSS, and JavaScript to build the user interface and make it interactive.
Backend development, on the other hand, refers to the development of the server-side of a web application, including the logic and functionality that runs on the server. It typically involves the use of programming languages such as Java, Python, or Node.js to build the backend logic and to interact with databases or other external services.
11. What is NPM?
NPM (short for Node Package Manager) is a package manager for the JavaScript programming language. It is the default package manager for the JavaScript runtime environment Node.js. NPM is used to manage dependencies (i.e., libraries and frameworks) for Node.js projects, as well as to publish and share packages with the community.
12. What are the modules in Node.js?
In Node.js, a module is a unit of code that is organized into a single file or a directory and that can be reused in other parts of a Node.js application. Modules in Node.js are used to encapsulate code and to provide a way to break up a large application into smaller, more manageable pieces. Modules can export functions, objects, or values, which can then be imported and used by other parts of the application.
13. What is the purpose of the module, Exports?
The exports object is a special object in Node.js that is used to expose functions, objects, or values from a module so that they can be used by other parts of the application. For example, a module might define a function and then use the exports object to make it available to other parts of the application:
It allows developers to use JavaScript on the server side, which can be convenient for those who are already familiar with the language.
It is lightweight and efficient, making it well-suited for applications that require real-time communication or need to handle a large number of concurrent connections.
It has a large and active community of developers, which means that there are many open- source libraries and tools available for use.
It is well-documented and has good support for a variety of platforms and operating systems.
Some of the cons of Node.js include:
It is not well-suited for CPU-intensive tasks, as it uses a single-threaded model and can only use a single CPU core at a time.
It can be more difficult to debug than other backend technologies, as errors in asynchronous code can be difficult to track down.
It can be more difficult to scale than other technologies, as it uses a single-threaded model and does not support horizontal scaling out of the box.
19. What is the command used to import external libraries?
The require() function is used to import external libraries in Node.js. For example, to import the lodash library, you would use the following code:
This will make the functions and objects from the lodash library available for use in your Node.js application.
20. What does event-driven programming mean?
Event-driven programming refers to a programming paradigm in which the flow of the program is determined by events or triggers. In an event-driven system, the program waits for external events to occur, such as a user clicking a button or a network request completing, and then responds to those events by executing the appropriate code. Event-driven programming is often used in applications that require real-time communication or the ability to handle a large number of concurrent connections, as it allows the program to respond to events as they happen without the need to continuously poll for new events.