Node.js Flashcards
What is Node.js?
-a program that allows JavaScript to be run outside of a web browser
What can Node.js be used for?
- it is used to build scalable network applications
- it is also commonly used to build back ends for Web applications, command-line programs, or any kind of automation that developers wish to perform
What is a REPL?
- Read–eval–print loop
- an interactive environment that takes single user inputs, executes them, and returns the result to the user
When was Node.js created?
2009
What is the process object in a Node.js program?
The process object is a global that allows access to, and control over, the current Node.js process
How do you access the process object in a Node.js program?
As a global, it is always available to Node.js applications without using require().
It can also be explicitly accessed using require():
const process = require(‘process’);
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
What is a JavaScript module?
-a single .js file that contains everything necessary to execute only one aspect of the desired functionality
What values are passed into a Node.js module’s local scope?
exports, require, module, __filename, __dirname
Give two examples of truly global variables in a Node.js program.
process object, timer functions
What is the purpose of module.exports in a Node.js module?
-lets you carry forth (“export”) the code you need (functions, objects, strings, etc) onto other modules so they can be accessed there, too
How do you import functionality into a Node.js module from another Node.js module?
-use the “require” keyword at the top of the file, with the argument being the code that you want to import
const add = require(‘./add’);
What module does Node.js include for manipulating the file system?
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?
there are sync and async versions for all methods
- asynchronous examples: fs.writeFile & fs.readFile
- synchronous examples: fs.writeFileSync & fs.readFileSync