npm Flashcards Preview

Web Development > npm > Flashcards

Flashcards in npm Deck (20)
Loading flashcards...

What is npm?

npm(Node Package Manager) is the world's largest software registry. Open source developers from every continent use npm to share and borrow packages, and many organizations use npm to manage private development as well.

npm consists of three distinct components:

1. The Website: Use the website to discover packages, set up profiles, and manage other aspects of your npm experience. For example, you can set up organizations to manage access to public or private packages.

2. The Command Line Interface (CLI): The CLI runs from a terminal, and is how most developers interact with npm.

3. The Registry: The registry is a large public database of JavaScript software and the meta-information surrounding it.


What is a package?

A directory with one or more files of reusable code in it, and also has a file called package.json with some meta-data about this package.

If it has package.json, it is a package.


How can you create a package.json with npm?

~/repos/c0621-code-solutions/npm-intro (npm-intro)
λ npm init --yes


What is a dependency and how do you add one to a package?

A dependency is another package that your package needs in order to work.

You can add one to a package by:
npm install jquery


What happens when you add a dependency to a package with npm?

It downloads the package so it can be used.
The property dependencies get added to package.json:

"name": "npm-intro",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"jquery": "^3.6.0"


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?

Using the use/get method.


app.use(function (req, res, next) {
res.send('Hello World')
} )

app.use(function (req, res, next) {
console.log('Time: %d', ))
next( )
} )

It happens when I request is received in the server.
Event listener for requests.


Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?

req and res.

request and response.

req is a data-model for the request message:
GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
User-Agent: HTTPie/1.0.3


What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?



What does the express.json( ) middleware do and when would you need it?

express.json( ) is a method inbuilt in express to recognize the incoming Request Object as a JSON Object. This method is called as a middleware in your application using the code: app.use(express.json( ));

If the request includes JSON, use it.


What is the significance of an HTTP request's method?

It defines what is to be done with the data.

The method name is just for semantics.


What is Webpack?

It's a tool that lets you bundle your JavaScript applications (supporting both ESM and CommonJS), and it can be extended to support many different assets such as images, fonts and stylesheets.

Bundles modules.


How do you add a devDependency to a package?

npm install --save-dev webpack


npm i -D webpack


What is an NPM script?

An npm script is a convenient way to bundle common shell commands for your project.

Command line shortcuts.


How do you execute Webpack with npm run?

Add a script in package.json


"scripts": {
"build": "webpack",
"test": "echo \"Error: no test specified\" && exit 1"


What kind of modules can Webpack support?

ECMAScript modules. CommonJS modules. AMD modules.


What does express.static( ) return?

It returns a middleware function. Programmed to look in directory and sort.


What is the local __dirname variable in a Node.js module?

The directory name of the current module. This is the same as the path.dirname( ) of the __filename.

__dirname is an absolute path.


What does the join( ) method of Node's path module do?

The path.join( ) method joins all given path segments together using the platform-specific separator as a delimiter( / ), then normalizes the resulting path.