NPM/Express/Babel Flashcards
What is NPM?
Node package manager, software registry that makes it easy for JS developers to share reusable code to solve problems
- website, command line client, registry
What is a package?
directory with one or more files inside and package.json file
How can you create a package.json with npm?
npm init -y (for default) in current directory
What is a dependency and how do you add one to a package?
Any other packages that your package depends on
**npm install package-name
What happens when you add a dependency to a package with npm?
- the package name is added under “dependencies” in package.json
- npm will downloads listed dependencies under node-modules directory
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?
app.listen
How do you mount a middleware with an Express application?
app.use()
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
request and response objects
What is the purpose of the Content-Type header in HTTP request and response messages?
In a response, the header tells the client what kind of file type the returned content is
In a request, the client tells the server what kind of information is being sent
What does express.static() return?
a middleware function that returns static files such as images, CSS files, and JavaScript files in the specified root directory
What is the local __dirname variable in a Node.js module?
full directory name of current module or absolute path
What does the join() method of Node’s path module do?
concatenates individual segments or strings together to form a file path
middleware functions (express)
functions that have access to the request object (req), the response object (res), and 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 does the express.json() middleware do and when would you need it?
It parses incoming requests from JSON
Returns middleware that only parses JSON and only looks at requests where the Content-Type header matches the type option.
only need this that is supposed to receive json
What is the significance of an HTTP request’s method?
Tells the server what the client is trying to do (ex. get information, post information, delete information, etc)
What is Webpack?
a tool that allows let us take JS modules and bundle them together
**module butler
How do you add a devDependency to a package?
npm install –save-dev webpack
npm install –save-dev
What is an NPM script?
Written in package.json as key/value pair, a script to help to automate tasks (command line command) name: key, value: what you want to execute
How do you execute Webpack with npm run?
List it as a script under package.json “scripts”
How are ES Modules different from CommonJS modules?
No export.modules or require
**export keyword in front of whatever you want to export, then import _ from “file path”
What kind of modules can Webpack support?
ES2015 import, CommonJS require, AMD define/require, @import statment css/sass/less, img url in stylesheet url() or HTML img src file
What is Babel?
JavaScript compiler/toolchain used to convert JS code to older versions to be compatible with older browsers and environments
What is a Plug-in?
a software component that adds a specific feature to an existing computer program.
What is a Webpack loader?
transformations that are applied to the source code of a module. They allow you to pre-process files as you import or “load” them
How can you make Babel and Webpack work together?
in your webpack config object:
- loader: babel-loader
- Options property -> plugins: [] array of wanted plugins