Node.js Flashcards
What is Node.js?
Program that allows JavaScript to run outside of a web-browser
What can Node.js be used for?
- Build back ends for web apps
- Command-line programs
- Any kind of automation that developers wish to perform
What is a REPL?
o Read-eval-print loop
o Interactive programming environment that takes single user inputs and executes them to return the result to the user (executed piecewise)
For example, the browser console
When was Node.js created?
2009
Back-end languages:
JavaScript Java Python PHP Ruby Go C++ C# (runs in .NET which is a framework)
What is a computer process?
Instance of a program running in a computer
Why should a full stack Web developer know that computer processes exist?
Because full stack web applications require multiple processes to work together concurrently for it to be useable (multiple processes have to be up and running to properly deal with the app’s clients, servers and databases)
What is the process object in a Node.js program?
Global object that provides information about/control over the current Node.js process
How do you access the process object in a Node.js program?
process
What is the data type of process.argv in Node.js?
Array of strings
What is a JavaScript module?
A single .js file
What values are passed into a Node.js module’s local scope?
o exports o require o module o \_\_filename o \_\_dirname
Give two examples of truly global variables in a Node.js program.
o console o process o Object o Undefined o global
What is the purpose of module.exports in a Node.js module?
How do you import functionality into a Node.js module from another Node.js module?
require(‘./filename’)
What is the JavaScript Event Loop?
How asynchronous callbacks are put back into the call stack when the call stack is clear
What is different between “blocking” and “non-blocking” with respect to how code is executed?
o Blocking = Stack is occupied and prevents other code from running (like for-loops)
o Non-blocking = Stack is clear and event loop can occur
What is a directory?
o Path to where the file is located
o Specific type of file that lists other files
What is a relative file path?
A path to a file starting from the current directory
What is an absolute file path?
A path to a file starting from the root (for windows, from the drive name)
What module does Node.js include for manipulating the file system?
fs (file system)
What method is available in the Node.js fs module for writing data to a file?
writeFile( )
Are file operations using the fs module synchronous or asynchronous?
Both
What is npm?
Makes it easier for javascript developers to share the code they have created to solve particular problems
o stands for node package manager
o Made of 3 parts: Website, CLI and registry
What is a package?
File or directory that is described by a package.json file
How can you create a package.json with npm?
npm init –yes
What is a dependency and how to you add one to a package?
a package you download to run your program; the package should generally have code to implement in your own code
o A npm package installed using npm install
o npm install
What happens when you add a dependency to a package with npm?
A new directory of the package gets created within the current directory
How do you add express to your package dependencies?
npm install express
What Express application method starts the server and binds it to a network PORT?
.listen( )
How do you mount a middleware with an Express application?
.use( )
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
req
res
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json
What does the express.json() middleware do and when would you need it?
o It’s used to recognize incoming requests as JSON object
o To parse incoming request bodies
What is the significance of an HTTP request’s method?
o It allows us to express our intent – it’s just a string (does not have any special functions or actions)
o Helps capture the value we want to pass to perform a certain action
Note: There is no intrinsic meaning in an http request method
What does express.static() return?
Return a middleware function that shows the path to a directory so its contents can become publicly accessible
What is the local __dirname variable in a Node.js module?
Absolute path to a directory containing the current module
What does the join() method of Node’s path module do?
Joins strings together to create a path to a directory