Node.js & Express.js Flashcards
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 directory?
A folder that houses grouped files.
What is a relative file path?
A file location inside of the current directory. A fil relative to the current folder.
What is an absolute file path?
The full file path or URL, in this instance it’s the full path from the system’s root.
Do not hard code – it’ll break on another computer. Avoid using hard coded absolute file paths.
What module does Node.js include for manipulating the file system?
Fs module.
What is npm?
npm is the world’s largest software registry that allows JavaScript developers to share code they created to solve specific problems and allows other developers to use that code. It also makes it easy to keep that code up to date. It consists of 3 components, the npm website, the cli, and the registry.
What is a package?
Packages, or modules, are directories that include a file called package.JSON with meta data about the package, which may contain a program. Usually contains tools needed for a program to work the way we want them to.
How can you create a package.json with npm?
npm init command – it just creates a file. To create a default package.json, you must navigate to the root of the directory you want to install the package in, then in the terminal, run npm init –yes command.
What is a dependency and how do you add one to a package?
It is a program or package that a given module requires, or depends upon, to work. To add one, you run the npm install command with the dependency you want to install.
What happens when you add a dependency to a package with npm?
When you run the npm install command, the dependencies get installed to the local node_modules folder, each as a subfolder, and gets added to the package.json file’s dependency object.
By default, npm install will install all modules listed as dependencies in package.json.
How do you add express to your package dependencies?
npm install express command (after npm init command).
What Express application method starts the server and binds it to a network PORT?
The .listen() method:
const express = require('express'); const app = express();
app.listen(3000, () => { // eslint-disable-next-line no-console console.log('Express server listening on port 3000'); });
How do you mount a middleware with an Express application?
With the .use() method of the app object.
app.use([path,] callback [, callback…])
Mounts the specified middleware function or functions at the specified path: the middleware function is executed when the base of the requested path matches path.
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
The request and response objects.