npm Flashcards
What is NPM?
Node package manager - a way to reuse/use code from other developers and also to share your code, which makes it easy to manage the different versions of code
- website
- the Command Line Interface (CLI)
- the registry
- 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.
- The CLI runs from a terminal, and is how most developers interact with npm.
- 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 and it contains the file package.json
How can you create a package.json with npm?
- go to the root directory of the package.
2. npm init –yes
What is a dependency and how to you add one to a package?
Packages required by your application in production.
You can add to a package by “npm install (package-name)”
What happens when you add a dependency to a package with npm?
the dependency key will be listed in the package’s 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
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
request object (req) response object (res)
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 determines the different actions that can be done depending on the method.
What does the express.json() middleware do and when would you need it?
It parses incoming requests with JSON payloads and returns the object containing parsed data on req.body.
You would need it when your app needs to parse JSON request bodies.
What is Webpack?
webpack bundles your JS application by automatically building your dependency graph based on what is imported and exported
How do you add a devDependency to a package?
–save-dev
example:
npm install –save-dev
What is an NPM script?
it is a property of package.json and can be executed by running npm run; CLI command you can run