Tooling & Package Management Flashcards

npm/yarn Environment Configs Dotenv & Cross-env Linting & Prettier Scripts & Lifecycle Hooks (49 cards)

1
Q

What is npm?

A

npm (Node Package Manager) is the default package manager for Node.js that manages dependencies and scripts for JavaScript projects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Yarn?

A

Yarn is an alternative package manager to npm, developed by Facebook, known for faster installs and deterministic dependency resolution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the purpose of a package.json file?

A

The package.json file contains metadata about a project and manages dependencies, scripts, and project configuration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a package-lock.json or yarn.lock file?

A

These files lock the dependency tree to specific versions, ensuring consistent installs across environments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are environment variables?

A

Environment variables are dynamic values that can affect the way running processes behave, commonly used for configs like API keys.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is dotenv?

A

dotenv is a zero-dependency module that loads environment variables from a .env file into process.env.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is cross-env?

A

cross-env allows setting environment variables in scripts across platforms (Windows, Linux, macOS).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is linting in JavaScript?

A

Linting is the process of statically analyzing code to find bugs, style issues, or bad practices using tools like ESLint.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Prettier?

A

Prettier is an opinionated code formatter that enforces a consistent code style across your project.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the benefit of using linting tools?

A

They help enforce code quality and consistency, prevent bugs, and make code easier to maintain.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are npm scripts?

A

npm scripts are custom commands defined in the package.json file that can automate tasks like build, test, or lint.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are lifecycle hooks in npm?

A

Lifecycle hooks are special npm script names that automatically run at specific points like install, start, or test.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you define a start script in npm?

A

In package.json: "scripts": { "start": "node index.js" }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the advantage of using Yarn over npm?

A

Yarn offers faster and more reliable installations, caching, and offline support.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a disadvantage of using Yarn?

A

Yarn adds another layer of tooling, which may complicate workflows for teams already using npm.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a best practice for managing env configs?

A

Store secrets in .env, use dotenv to load them, and never commit .env files to version control.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a use case for cross-env?

A

Ensuring scripts that set environment variables work across platforms (e.g., setting NODE_ENV in Windows).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What impact do scripts have on system design?

A

Scripts help standardize and automate repetitive tasks like linting, testing, or deployment, aiding CI/CD pipelines.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Give an example of a lint script.

A

"lint": "eslint ."

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Give an example of using cross-env in scripts.

A

"scripts": { "start": "cross-env NODE_ENV=production node app.js" }

21
Q

What architectural benefit do linting tools provide?

A

They promote clean, maintainable codebases and support scalable development by enforcing rules.

22
Q

How can tooling improve performance and fault tolerance?

A

By catching issues early with linting and environment configs, and reducing errors in production builds.

23
Q

How do you monitor tooling setup in CI/CD pipelines?

A

Run lint, test, and build scripts as part of CI jobs; log outputs and enforce failures on issues.

24
Q

What are some real-world tradeoffs with tooling?

A

Tooling adds overhead and setup time but improves consistency and reduces bugs in the long run.

25
What is a common interview question about npm?
What is the difference between dependencies and devDependencies in package.json?
26
What’s a gotcha when using dotenv?
dotenv only loads variables at runtime, so changes in `.env` don't apply until the server restarts.
27
What’s a gotcha when using scripts with environment variables on Windows?
Setting env vars directly fails; use cross-env to ensure compatibility.
28
What’s the role of devDependencies?
Packages only needed for development (e.g., testing, linting tools) are listed in devDependencies.
29
What’s the difference between `npm install` and `npm ci`?
`npm install` installs dependencies, possibly modifying package-lock; `npm ci` installs exactly what's in lock file and is used in CI.
30
Why use Prettier over ESLint for formatting?
Prettier is opinionated and enforces consistent formatting automatically; ESLint is more focused on code quality and best practices.
31
What’s the difference between ESLint and Prettier?
ESLint finds potential problems in code, while Prettier formats code for style and consistency.
32
What is a common .npmrc configuration?
You can use .npmrc to configure registry, cache, and authentication settings for npm installs.
33
What is a potential issue with conflicting ESLint and Prettier rules?
They can contradict each other; use eslint-config-prettier to disable formatting rules in ESLint.
34
Why is script standardization important in teams?
It ensures everyone uses the same commands and setups, reducing onboarding time and preventing errors.
35
What is a recommended structure for env configs?
Use `.env`, `.env.development`, `.env.production`, and load them conditionally based on NODE_ENV.
36
What’s the impact of tooling on debugging?
Better tooling helps catch syntax and logic errors early, reducing time spent debugging.
37
What is the purpose of `npx`?
npx runs binaries from npm packages without globally installing them.
38
What’s a disadvantage of over-configuring tooling?
It can slow down the development process and create steep learning curves for new developers.
39
What’s a good practice for Prettier and ESLint setup?
Integrate them with your editor and run them in pre-commit hooks or CI.
40
What are husky and lint-staged used for?
husky sets up Git hooks, and lint-staged runs linters on staged files before committing to improve code quality.
41
How do you enforce script consistency across devs?
Use scripts in `package.json` and optionally enforce with tools like `npm-run-all` or custom shell scripts.
42
What is a typical use case for npm lifecycle scripts?
Run build steps before starting the server or cleaning directories before testing.
43
What is the difference between `npm run` and running a script directly?
`npm run` uses the local node_modules/.bin path, making locally installed tools available without global install.
44
Why should you not commit `.env` files?
They can contain sensitive data like API keys and credentials, which should not be exposed publicly.
45
What’s the use of `.env.example`?
It provides a template for required env variables without exposing actual secrets.
46
What happens if a required env var is missing?
Your app might crash or behave unexpectedly; always validate required env vars on startup.
47
What’s the difference between `npm uninstall` and `npm remove`?
They are aliases; both remove a package from node_modules and package.json.
48
What are peerDependencies?
peerDependencies are used when a package expects a specific version of another package to be installed by the consumer.
49
What is the advantage of using lock files in npm/yarn?
They ensure consistent dependency versions across different environments and installations.