Node.js Flashcards
What is Node.js?
Node.js is a program that allows JavaScript to be run outside of a web browser.
What can Node.js be used for?
Node.js is 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 (REPL) is a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user
When was Node.js created?
2009 by Ryan Dahl
What back end languages have you heard of?
PHP(scripting), Python(scripting), Ruby(scripting), C#(compiled), C++(compiled), Java (compiled), Swift(compiled/scripting), objective-c (compiled) , perl(scripting), javascript(script), go (complied), erlang(compiled), elixir (compiled)
What is a CLI?
A Command Line Interface (CLI) processes commands to a computer program in the form of lines of text.
What is GUI?
A Graphical User Interface (GUI) is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indications instead on text based user interfaces
Give at least one use case for - man - command
To look up the user manual for any command (name, synopsis, description)
Give at least one use case for - cat - command
- Print files on the standard output.
- Concatenate files - combine the contents of those files.
- Combine files and write the result to a new file using >
Give at least one use case for - ls - command
Display/print list directory contents
Give at least one use case for - pwd - command
Display/print the full file name of the current working directory
Give at least one use case for - echo - command
Display a line of text / Echo/print the line of text to the standard output
Give at least one use case for - touch - command
- make a file
2. update the access and modification times of each file to the current time
Give at least one use case for - mkdir - command
Make directories
Give at least one use case for - mv - command
- Move files
2. Rename files
Give at least one use case for - rm - command
Remove files or directories - is instantaneous and permanent
Give at least one use case for - cp - command
Copy files and directories
What is a computer process?
A process is the instance of a computer program that is being executed by one or many threads. It contains the program code and its activity. Depending on the operating system (OS), a process may be made up of multiple threads of execution that execute instructions concurrently.
While a computer program is a passive collection of instructions, a process is the actual execution of those instructions. Several processes may be associated with the same program.
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
400+
Why should a full stack Web developer know that computer processes exist?
Full stack Web development is based on making multiple processes work together to form one application, so having at least a cursory awareness of computer processes is necessary
What is the process object in a Node.js program?
The process object is a global that provides information about, and control over, the current Node.js process.
How do you access the process object in a Node.js program?
Process is a global object so you can just reference it - console.log(process)
What is the data type of process.argv in Node.js?
An array of strings
How to you write to the standard out of a Node.js program
use console.log( )
What is a JavaScript module?
In JavaScript, a “module” is a single .js file.
What values are passed into a Node.js module’s local scope?
exports, require( ), module, __filename, __dirname,
Give 2 examples of truly global variables in a Node.js program
Console, global, process, setInerval/Timeout and clearInterval/Timeout
What is the purpose of module.exports in a Node.js module?
Module exports are the instruction that tells Node.js which bits of code (functions, objects, strings, etc.) to “export” from a given file so other files are allowed to access the exported code
How do you import functionality into a Node.js module from another Node.js module?
const variable = require(./relativeFilePath )
What is the JavaScript Event Loop?
The Event Loop takes callbacks from the callback queue and pushes them to the stack as long as the stack is clear.
What is different between “blocking” and “non-blocking” with respect to how code is executed?
“blocking” means script that is executed on the stack, It is “blocking” as long as it is on the stack. It is “non-blocking” when it’s not on the stack
What is a directory?
A special type of file whose whole job is to point to other files… a folder
What is a relative file path?
A path to a file based of the current location (does not start with a /)
What is an absolute file path?
The whole file path starting with a slash (the root)
What module does Node.js include for manipulating the file system?
The fs module
What method is available in the Node.js fs module for writing data to a file?
fs.writeFile( ) method
Are file operations using the fs module synchronous or asynchronous?
fs.writeFile( ) is asynchronous. All file system operations have synchronous and asynchronous forms.
What is NPM
NPM is a website, a command line interface, ; a software registry that allows developers to share their code so others can reuse that code.
What is a package?
A package is a bit of reusable code - it’s a file in a directory with one or more files in it including a file called package.json with meta data about this package
How can you create a package.json with npm?
On the command line navigate to the rood directory f you package. Then use the npm init command with the –yes or -y flag
What is a dependency and how to you add one to a package?
A dependency is a package needed for your application to work, and you add one with the npm install command
What happens when you add a dependency to a package with npm?
- Your package.json file gets updated with the dependency added under dependencies property.
- The content of that package gets downloaded from the npm registry and put in a node_modules directory
What is Webpack?
Webpack is a tool that lets you bundle your JavaScript applications.
How do you add a devDependency to a package?
“devDependencies”: Packages that are only needed for local development and testing.
npm install package-name –save-dev
OR
npm install package-name -D
What is an NPM script?
The “scripts” property of of your package.json file supports a number of built-in scripts and their preset life cycle events as well as arbitrary scripts.
scripts are command line commands
How do you execute Webpack with npm run?
Add “build”: “webpack” to your package.json scripts property then use command – npm run build
How are ES Modules different from CommonJS modules?
ES Modules syntax is more compact than CommonJS, structure can be statically analyzed, the support for cyclic dependencies is better than CommonJS
What kind of modules can Webpack support?
ECMAScript modules, AMD Modules, CommonJS
How can you make webpack automatically recompile your JSX code whenever changes are made?
Add the script
“watch”: “webpack –watch –mode=development –devtool=source-map”
to your package.json