Node.js Flashcards
(35 cards)
What is the process object in the Node.js program?
The process object is a global that provides information about, and control over, the current Node.js process. As a global, it is always available to Node.js applications without using require().
How do you access the process object in a Node.js program?
Just call process.
What is the data type of process.argv in Node.js?
It returns an array containing the command line arguments when the Node.js process was launched. The first element will be process.execPath. The second element will be the path to the JS file being executed. The remaining elements will be any additional command line arguments.
What is process.execPath?
The process.execPath property returns the absolute pathname of the executable that started the Node.js process.
What is a JavaScript module?
In the Node.js module system, each file is treated as a separate module.
What values are passed into a Node.js module’s local scope?
exports (object), require (function), module (object), __filename (string), __dirname (string)
Give two examples of truly global variables in a Node.js program.
console, process
What is the JS Event Loop?
Its job is to continuously watch both the stack and message queue. When the stack becomes empty, it checks the message queue to see if there are any messages waiting to be processed. If there are, it puts them into the call stack one at a time and executes them. Each message is associated with a function such as a callback or an event.
What is a directory?
is a special type of file that holds information about more directories and files
What is a relative file path?
a file relative to the current page
What is an absolute file path?
a full URL to a file
What module does Node.js include for manipulating the file system?
We include the fs module
What method is available in the Node.js fs module for writing data to a file?
fs.writeFile
Are file operations using the fs module synchronous or asynchronous?
asynchronous
What is JSON?
JSON is a text-based data format following JS object syntax, which was popularized by Douglas Crockford. JSON exists as a string.
What are serialization and deserialization?
Converting a string to a native object is called deserialization, while converting a native object to a string so it can be transmitted across the network is called serialization.
Why are serialization and deserialization useful?
Useful when you want to transmit data across a network
How to you serialize data into a JSON string using JavaScript?
JSON.stringify()
How do you deserialize a JSON string using JavaScript?
JSON.parse()
What is NPM?
npm is a package manager for the JS programming language. It’s a way to reuse code from other developers and also a way to share your code with them and it makes it easy to manage the different versions of code.
What is a package?
A package in Node.js contains all the files you need for a module. Modules are JS libraries you can include in your project.
Video: Reusable codes == packages(or sometimes module)
A package is a directory with one or more files in it that also has a file called package.json with some metadata about this package.
How can you create a package.json with npm?
Go to the directory where you want to create the package.json file and then run npm init –yes
What is a dependency and how do you add one to a package?
When you install an npm package using npm install , you are installing it as a dependency. The package is automatically listed in the package.json file, under the dependencies list.
The dependencies are the modules that the project relies on to function properly.
What happens when you add a dependency to a package with npm?
The packages listed under the dependencies are required by your application in production.