Tooling & Package Management Flashcards
npm/yarn Environment Configs Dotenv & Cross-env Linting & Prettier Scripts & Lifecycle Hooks (49 cards)
What is npm?
npm (Node Package Manager) is the default package manager for Node.js that manages dependencies and scripts for JavaScript projects.
What is Yarn?
Yarn is an alternative package manager to npm, developed by Facebook, known for faster installs and deterministic dependency resolution.
What is the purpose of a package.json file?
The package.json file contains metadata about a project and manages dependencies, scripts, and project configuration.
What is a package-lock.json or yarn.lock file?
These files lock the dependency tree to specific versions, ensuring consistent installs across environments.
What are environment variables?
Environment variables are dynamic values that can affect the way running processes behave, commonly used for configs like API keys.
What is dotenv?
dotenv is a zero-dependency module that loads environment variables from a .env
file into process.env
.
What is cross-env?
cross-env allows setting environment variables in scripts across platforms (Windows, Linux, macOS).
What is linting in JavaScript?
Linting is the process of statically analyzing code to find bugs, style issues, or bad practices using tools like ESLint.
What is Prettier?
Prettier is an opinionated code formatter that enforces a consistent code style across your project.
What is the benefit of using linting tools?
They help enforce code quality and consistency, prevent bugs, and make code easier to maintain.
What are npm scripts?
npm scripts are custom commands defined in the package.json file that can automate tasks like build, test, or lint.
What are lifecycle hooks in npm?
Lifecycle hooks are special npm script names that automatically run at specific points like install, start, or test.
How do you define a start script in npm?
In package.json: "scripts": { "start": "node index.js" }
What is the advantage of using Yarn over npm?
Yarn offers faster and more reliable installations, caching, and offline support.
What is a disadvantage of using Yarn?
Yarn adds another layer of tooling, which may complicate workflows for teams already using npm.
What is a best practice for managing env configs?
Store secrets in .env
, use dotenv
to load them, and never commit .env
files to version control.
What is a use case for cross-env?
Ensuring scripts that set environment variables work across platforms (e.g., setting NODE_ENV in Windows).
What impact do scripts have on system design?
Scripts help standardize and automate repetitive tasks like linting, testing, or deployment, aiding CI/CD pipelines.
Give an example of a lint script.
"lint": "eslint ."
Give an example of using cross-env in scripts.
"scripts": { "start": "cross-env NODE_ENV=production node app.js" }
What architectural benefit do linting tools provide?
They promote clean, maintainable codebases and support scalable development by enforcing rules.
How can tooling improve performance and fault tolerance?
By catching issues early with linting and environment configs, and reducing errors in production builds.
How do you monitor tooling setup in CI/CD pipelines?
Run lint, test, and build scripts as part of CI jobs; log outputs and enforce failures on issues.
What are some real-world tradeoffs with tooling?
Tooling adds overhead and setup time but improves consistency and reduces bugs in the long run.