Node Flashcards
What is Node.js?
a JavaScript runtime that is asynchronous and event driven.
Environment that lets us execute JavaScript code that doesn’t use a browser
What can Node.js be used for?
It can be used to write command line tools and server-side scripting, making JavaScript to be the language for both server and client side
What is a REPL?
Read-Eval-Print-Loop. Takes user-made input and returns it one line at a time
When was Node.js created?
May 27, 2009
What back end languages have heard of?`
Python, JavaScript, Java, Ruby, C#, C++, PHP
What is the ‘process’ object in a Node.js program?
Its a global that provides info about and control over the current Node.js process
How do you access the ‘process’ object in a Node.js program?
Use the process variable
What is the data type of ‘process.argv’ in Node.js?
Returns an array
What is a JavaScript module?
It is a single ‘.js’ file meant to separate out some functionality
What values are passed into a Node.js module’s local scope?
‘module,’ ‘require,’ ‘exports,’ ‘__dirname,’ ‘__filename’
Give 2 examples of truly global variables in a Node.js program.
- global
- console
- setTimeout()
- clearInterval()
What is the purpose of ‘module.exports’ in a Node.js module?
Allows data types to be returned from a module called by using ‘require()’
How do you import functionality into a Node.js module from another Node.js module?
the require() function.
The source module contains the desired functionality within its code, followed by exports.name = name
The calling module contains the name, using a require()
What is a directory?
A file that lists locations to other files
What is a relative file path?
Set of directions from the current directory to its destination
What is an absolute file path?
A path to a file that has the entire path shown, from its root element to its final destination
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?
Asynchronous
What is a client?
A requester of services from a server
What is a server?
A provider of services to one or many clients (does the processing)
Which HTTP method does a browser issue to a web server when you visit a URL?
‘GET’
What is on the first line of an HTTP request message?
- The type of request (
GET
,POST
,PUT
), known as an HTTP method - The URL
- The HTTP version
What is on the first line of an HTTP response message?
- The protocol
- The status code (200, 404, etc)
- The human readable status (Success, file not found, etc.)
What are HTTP headers?
A space for clients/servers to pass additional information about a request to each other, known as meta info
Is a body required for a valid HTTP message?
No, it is not required
What is NPM?
Nope Package Manager
What is a package?
a file or directory
How can you create a ‘package.json’ with ‘npm’?
Use the CLI command npm init --yes
What is a dependency and how do you add one to a package?
- A dependency is a package from an external source that is used in your program, making your program dependent on it
- The
npm install (package name)
command automatically adds the dependency to thepackage.json
file. Otherwise, include it in thepackage.json
file.
What happens when you add a dependency to a package with ‘npm’?
It automatically adds the dependency into the package.json
file
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() method
How do you mount a middleware with an Express application?
the Use method of the App object
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
-
req
- the request object -
res
- the response object -
next()
- the next middleware function in the application’s request-response cycle
What is the appropriate Content-Type
header for HTTP messages that contain JSON in their bodies?
application/json
What is the significance of an HTTP request’s method?
It signifies the intent of the request, and can help a server developer design how a request should be handled
What does the ‘express.json()’ middleware do and when would you need it?
Allows for parsing of JSON requests on requests made to an endpoint (route)
You need it when you are expecting to receive JSON requests and want to work with the JSON data as a JavaScript object
What is Webpack?
A module bundler, compiling many files into one file
How do you add a ‘devDependency’ to a package?
npm install –save-dev
What is an NPM script?
They are scripts made available in the package.json
file that allow you to run commands from NPM
How do you execute Webpack with ‘npm run’?
Add a build
to the NPM package.json
’s scripts
section, with the command being just webpack
What does ‘express.static()’ return?
A function serveStatic
What is the local ‘_dirname’ variable in a Node.js module?
The absolute path directory name of the module
What does the ‘join()’ method of Node’s ‘path’ module do?
Joins strings together into a coherent path