ui final Flashcards
What is the use of the ‘os’ module in Node.js?
deals with operating systems
What is the purpose of the “path” module in Node.js?
handles file paths
Which command is used to install a package globally in Node.js using npm?
Apply -g
How do you handle file operations in Node.js?
“fs”
Which one is a key feature of Node.js?
Uses an event-driven, non-blocking architecture that works on single
threaded model and processes events using callbacks.
* For example, HTTP calls made to server from Node.js code is non-blocking,
asynchronous, does not wait for the response, and handles the response when it
comes, using a callback model.
* This makes Node.js extremely effective and scalable for managing concurrent
connections and processes.
Which of the following method of fs module is used to read a file in Node.js?
fs.readFile()
Which one of the following command will display all globally installed packages in npm?
npm ls –depth=0 -global
What does the “require” function in Node.js do?
a built-in function to include external modules
that exist in separate files
How do you append data to a file in Node.js?
fs.appendFile()
In the context of Node.js, what does the term “REPL” mean?
Read Evaluate Print Loop
How is callback function used in Node.js?
A callback is a function that is invoked after the asynchronous
operation is finished and is supplied as an input to another function.
* Asynchronous operations in Node.js, such as reading files, making
network requests, or querying databases, are non-blocking,
– This means the code doesn’t wait for the operation to complete before moving
on to the next line.
– Instead, it initiates the operation and continues executing the remaining code.
– When the asynchronous operation is complete, a callback function is called
to handle the result or any errors.
In Node.js, callbacks usually follow an error-first convention, where the first parameter of the callback
function is reserved for an error object.
– If no error occurred, this parameter will be null or undefined.
– If an error occurs, the subsequent parameters may hold additional data.
Which built-in module should you use to make a HTTP request in Node.js?
“http”
core modules of node.js
“fs”, which handles file system operations
* “http”, which creates HTTP servers and clients
* “path”, which handles file paths
* “os”, which deals with operating systems
How do you copy a file in Node.js?
fs.copyFile()
How do you read a file in Node.js?
fs.readFile()
How do you write a file in Node.js?
fs.writeFile()
Node Package Manager
npm is a package manager for node.js and is comprised of
three components
– Website - to discover packages (https://www.npmjs.com/)
– Command Line Interface (CLI) – to run commands from a terminal
* this is how most developers interact with npm.
* npm gets installed automatically when you install node.js
* npm –v //tells version of npm installed
– Registry - a large public database of JavaScript libraries and the
meta-information surrounding it.
External Modules
External modules produced by the community can be installed
and utilized in Node.js applications using package managers like
npm
* These modules are available for installation with a single
command and are kept in the npm registry.
* Examples of external modules include:
* Axios for sending HTTP requests,
* Moment.js for handling dates and times, and
* Mongoose for interacting with MongoDB databases
even-driven architecture of Node.js
Node.js is based on a non-blocking, event-driven architecture,
* as a result, it is extremely effective at managing concurrent connections and I/O activities.
* Node.js uses a “single-threaded, event-driven” architecture, which eliminates the
need to create new threads for every connection
* and instead allows a single event loop to manage multiple concurrent connections.
* An event loop is used by Node.js to control events and callbacks.
* The callbacks are triggered by the event loop, which continuously scans for events like incoming
requests or finished I/O operations.
* Node.js handles asynchronous actions by using callbacks as a common pattern.
* All I/O operations in Node.js are carried out asynchronously via callbacks,
* Enabling the program to carry out other tasks without waiting for the I/O activity to finish.
* Examples of this include reading from a file, sending an HTTP request, or querying a database.
execute the content of a JavaScript file (module) from inside
another JavaScript file, include the 2nd file in the first file
require(/relative path of the 2nd file) statement
Node.js built-in functions: exports
Exports allows you to call functions that are defined in one module
(calculator.js file) from another module (hello.js file) using module.exports
What does the @SpringBootApplication annotation do in Spring Boot?
annotation is used to bootstrap a Spring Boot
application. It is a combination of @Configuration, @EnableAutoConfiguration,
and @ComponentScan.
In Spring Boot, what is the purpose of the @ResponseBody annotation?
used to indicate that the return value of a controller method should be
serialized and sent as the response body. It is typically used with the @RequestMapping annotation.
In Spring Boot, what is the purpose of the @PathVariableannotation?
used to extract a variable from the URI of a request. It is typically used
with the @RequestMapping annotation.