Node.js Flashcards
What can Node.js be used for?
Node. js is primarily used for non-blocking, event-driven servers, due to its single-threaded nature. It’s used for traditional web sites and back-end API services, but was designed with real-time, push-based architectures in mind.
What is a REPL?
A read–eval–print loop (REPL), also termed an interactive toplevel or language shell, is a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user; a program written in a REPL environment is executed piecewise.
What is the process object in a Node.js program?
Global variable. The process object in Node.js is a global object that can be accessed inside any module without requiring it. There are very few global objects or properties provided in Node.js and process is one of them.
What is the data type of process.argv in Node.js?
The process.argv property returns an array containing the command line arguments passed when the Node.js process was launched. // The first element will be process.execPath. See process.argv0 if access to the original value of argv[0] is needed. The second element will be the path to the JavaScript file being executed. The remaining elements will be any additional command line arguments.
What is the data type of process.argv in Node.js?
What is a JavaScript module?
A module in JavaScript is just a file containing related code. I
n JavaScript, we use the import and export keywords to share and receive functionalities respectively across different modules. The export keyword is used to make a variable, function, class or object accessible to other modules.
What values are passed into a Node.js module’s local scope?
The five parameters — exports , require , module , __filename , __dirname are available inside each module in Node. Though these parameters are global to the code within a module yet they are local to the module (because of the function wrapper as explained above).
What is different between “blocking” and “non-blocking” with respect to how code is executed?
Blocking code occupied a call stack, and executed synchronously while non-blocking code execute asynchronously.
What is the JavaScript Event Loop?
JavaScript has a runtime model based on an event loop, which is responsible for executing the code, collecting and processing events, and executing queued sub-tasks. This model is quite different from models in other languages like C and Java.
What is an absolute file path?
path which includes root of the file. starts with a ‘/’
What method is available in the Node.js fs module for writing data to a file?
fs.writeFile(file, data[, options], callback)
What is NPM?
npm is the default package manager for the JavaScript runtime environment Node.js.
It consists of a command line client, also called npm, and an online database of public and paid-for private packages, called the npm registry.
/* npm consists of three distinct components:
the website
the Command Line Interface (CLI)
the registry */
What is a package (module)?
It is a directory with files in it => package.json and some reusable code
What is a dependency and how to you add one to a package?
A dependency is another package that your package needs in order to work. Dependencies are specified in your pubspec.
What is a dependency and how to you add one to a package?
A dependency is another package that your package needs in order to work. Dependencies are specified in your pubspec.
What Express application method starts the server and binds it to a network PORT?
The app. listen() function is used to bind and listen the connections on the specified host and port.
Network interface
Network interface is a piece of hardware on a computer that allows network connectivity (internet) evamples wifi card / adapter Lan card or adapter
- each network interface has own its own IP address
LAN: Local Area Network
Every network interface provides 2^16 “ports”
- the default (aka “well-known”) HTTP port is actually 80
- the defalt (aka “well-known”) Https port is actually 443
- any port number below 1024 requires “admin” privileges to use
What is the difference between library and framework ?
A library is a code someone wrote (or separate part of your codebase), a library should be reusable. A framework is a specific kind of library. A framework is different from library when is has “inversion of control”
Who calls who? A framework calls YOUR code, a library is called by your code. A framework describes WHEN to call your functions (you don’t cal them).
Middleware functions are functions that have access to the request object (req), the response object (res), and the next middleware function in the application’s request-response cycle. The next middleware function is commonly denoted by a variable named next.
Middleware functions can perform the following tasks:
Execute any code.
Make changes to the request and the response objects.
End the request-response cycle.
Call the next middleware function in the stack.
req (short for “request”)
a data model of the HTTP request massage (from the client)
res (short for “response”)
a data model of the HTTP request to the client
What does the express.json() middleware do and when would you need it?
json() is a built-in middleware function in Express. This method is used to parse the incoming requests with JSON payloads and is based upon the bodyparser. This method returns the middleware that only parses JSON and only looks at the requests where the content-type header matches the type option.
What is the significance of an HTTP request’s method?
HTTP defines a set of request methods to indicate the desired action to be performed for a given resource. Although they can also be nouns, these request methods are sometimes referred to as HTTP verbs.