A: npm is a package manager and repository for libraries, frameworks, and tools. It is the default package manager for Node.js projects and is installed along with Node.js. The NPM Registry hosts public and private packages, and the NPM CLI (Command-Line Interface) is used to manage dependencies and interact with this registry.
- Caret (^): Allows updates that do not change the first non-zero version number (e.g.,
^1.2.3allows1.x.xupdates but not2.x.x). - Tilde (~): Allows patch updates but locks the minor version (e.g.,
~1.2.3allows1.2.xbut not1.3.x).
Yarn is an alternative package manager.
npm init→ Creates apackage.jsonfile.npm init -y→ Skips setup and automatically generatespackage.json.
A: Parcel and Webpack are bundlers that optimize web applications by managing dependencies, improving performance, and reducing build time.
- HMR (Hot Module Replacement): Automatically updates modules without reloading the page.
- File Watcher Algorithm: Built with C++ for efficient tracking of file changes.
- Minification: Reduces file size by removing unnecessary code.
- Dev & Production Builds: Provides optimized builds for different environments.
- Super-fast building algorithm: Enhances development speed.
- Image Optimization & Caching: Improves performance and reduces reprocessing.
- Zero Configuration: Works out of the box with minimal setup.
- Automatic Code Splitting: Enhances load time efficiency.
npm install -D parcel # Install as a development dependency
npx parcel <entry_point> # Run development build
npx parcel build <entry_point> # Create a production buildA: .parcel-cache speeds up builds by storing project metadata and avoiding redundant reprocessing.
A: npx executes npm packages without installing them globally. It is included with npm (v5.2+).
A: The node_modules folder stores installed dependencies. It acts as a local database for required packages.
- Dependencies: Required for the app to function (e.g., React, Angular, Express).
- DevDependencies: Only needed during development (e.g., Parcel, Webpack, Jest).
npm install --save-dev # Adds to devDependencies
npm install --save # Adds to dependencies (default)A: Tree shaking removes unused code, optimizing the final bundle size.
A: HMR updates modules in real-time without a full page reload, retaining application state.
- HMR (Hot Module Replacement) – Updates modules without reloading.
- File Watcher Algorithm – Monitors file changes efficiently.
- Minification – Reduces file size for better performance.
- Image Optimization – Compresses images automatically.
- Caching during Development – Speeds up the build process.
A: .gitignore tells Git which files to exclude from version control.
# Ignore system files
.DS_Store
# Ignore dependencies
node_modules/
# Ignore environment files
.env
# Ignore logs
logs/- package.json: Contains project metadata, dependencies, and scripts.
- package-lock.json: Locks exact versions of installed dependencies to ensure consistency.
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
}^18.2.0: Updates minor/patch versions but not major versions.~18.2.0: Updates only patch versions.
It ensures consistent dependencies across environments. Modifying it manually can break installations.
A: No, because it is large (100MB+) and can be recreated using npm install. Use .gitignore to exclude it.
A: The dist/ folder contains the optimized, minified, and production-ready build of the application.
A: Browserslist configures supported browsers for frontend apps, optimizing compatibility.
"browserslist": [
"> 0.5%",
"last 2 versions",
"not dead"
]This chapter covers essential topics for setting up a React app using modern tools like npm, Parcel, and Browserslist. 🚀