Node.js Flashcards
What is Node.js?
Runs on V8 engine and allows JS to run outside of a web browswer
What can Node.js be used for?
Access JS in the backend
What is a REPL?
Read Eval Print Loop - simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user. (ex: browser console)
When was Node.js created?
2009
What back end languages have you heard of?
Scripting languages: PHP, Python, Ruby, Perl, Lua
Systems languages: C, C++, Rust, D, Zig
Byte code languages: Java, C#,
What is a computer process?
Instance of a program being executed.
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
100 or more
Why should a full stack Web developer know that computer processes exist?
So they understand how much memory and moving parts of running. It’s part of potentially solving problems and writing viable code.
What is the process object in a Node.js program?
A model of the node.js object that is running.
How do you access the process object in a Node.js program?
Its a global object that can be accessed inside any module without requiring it.
What is the data type of process.argv in Node.js?
Array of strings
What is a JavaScript module?
Its a file (.js)
What values are passed into a Node.js module’s local scope?
exports, module, require, __filename, __dirname
Give two examples of truly global variables in a Node.js program.
Process, console, url
What is the purpose of module.exports in a Node.js module?
Defines dependencies on other modules and makes it available.
How do you import functionality into a Node.js module from another Node.js module?
Require function
What is a directory?
Folder that contains files and directs users where to go. It is essentially a file that lists other files.
What is a relative file path?
Points to another file within a file.
What is an absolute file path?
Path that points to a full url outside of the current page. Starts from root directory.
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?
Both
What is NPM?
Open source package manager to share and use code:. Refers to one of three things: cli, registry, and website
What is a package?
Directory with one or more files with a package.json file
How can you create a package.json with npm?
npm init
What is a dependency and how to you add one to a package?
Other packages that your code depends on
npm-install
What happens when you add a dependency to a package with npm?
Adds it to package.json file and adds a directory with code in it (ex: node_modules)
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?
use method
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
Content Type signifies what data type is in the body.
What is the significance of an HTTP request’s method?
Defines specific action between client and server
What does the express.json() middleware do and when would you need it?
Parses incoming requests to JSON. You would use when you have to handle a request with a body in JSON.
What does express.static() return?
Returns a middleware function
What is the local __dirname variable in a Node.js module?
Path to whatever directory you are in
What does the join() method of Node’s path module do?
Join all path segments together into one path separated by “/”