node Flashcards
What is Node.js?
its a javaScript runtime
What can Node.js be used for?
running JS in the command line
What is a REPL?
read eval print loop, playground for code
When was Node.js created?
may 27, 2009
What back end languages have you heard of?
“scripting languages” (interpreted)
python, javascript, ruby,
php, perl,
“compiled” (machine code translated)
c, c++ golang, haskell, crystal, rust
partially compiled(jvm) java, scala, closure, kotlin
partially compiled( c#, f#
What is the process object in a Node.js program?
info about and control over the current node process
How do you access the process object in a Node.js program?
grab out of thin air because it’s global
What is the data type of process.argv in Node.js?
array of strings
What is a JavaScript module?
a separate .js file used to separate and organize work that can be exported to and called upon by other modules and .js files in the directory
What values are passed into a Node.js module’s local scope?
Give two examples of truly global variables in a Node.js program.
process, console
What is the purpose of module.exports in a Node.js module?
creating a global data model that’s accessible from other modules in your file library
How do you import functionality into a Node.js module from another Node.js module?
assigning a require call with path to the file to a variable
What is a directory?
a special file that points to other files
What is a relative file path?
a path to a file from where you currently are
What is an absolute file path?
takes you from the root of the document to a specific file
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?
writeFile method
Are file operations using the fs module synchronous or asynchronous?
yes, you get to choose which version to use
What is NPM?
the website, the CLI, the registry
What is a package?
a directory with a package.json file and one or more files in it
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?
something you’re package will need to run,
npm install filename
What happens when you
add a dependency to a package with npm?
it downloads the node modules to your local system
How do you add express to your package dependencies?
npm i express
What Express application method starts the server and binds it to a network PORT?
.listen() method
How do you mount a middleware with an Express application?
app.use method
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
request obj and response obj(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?
to parse the incoming JSON requests, you’ll need it when you’re handling incoming JSON request bodies
hat is the significance of an HTTP request’s method?
it defines the desired action to be performed at the given resource or path
app.use is the catchall middleware
use them for anytime you want an express function to run everytime you run the stack
What is Webpack?
a module bundler to package JS and makes it all useable for the web
How do you add a devDependency to a package?
npm i –save-dev or npm i -D
What is an NPM script?
a property in package.json to store terminal commands
How do you execute Webpack with npm run?
npm run build
What does express.static() return?
a middleware function
What is the local __dirname variable in a Node.js module?
an absolute path to the directory name of the current module
What does the join() method of Node’s path module do?
joins path segments together into one useable filepath
What does fetch() return?
a promise that resolves the response
What is the default request method used by fetch()?
get
How do you specify the request method (GET, POST, etc.) when calling fetch?