# Browserify — Use Node.js require() in the Browser > A tool that bundles Node.js-style modules for the browser, enabling developers to use require() and npm packages in client-side JavaScript. ## Install Save as a script file and run: # Browserify — Use Node.js require() in the Browser ## Quick Use ```bash # Install npm install -g browserify # Bundle a file and its dependencies browserify main.js -o bundle.js # Watch for changes with watchify npm install -g watchify watchify main.js -o bundle.js -v # Use transforms browserify -t babelify main.js -o bundle.js ``` ## Introduction Browserify brought Node.js-style CommonJS modules to the browser by recursively analyzing require() calls and bundling all dependencies into a single file. It was the first widely adopted JavaScript module bundler and proved that npm packages could power front-end applications. ## What Browserify Does - Recursively resolves require() calls and bundles them into one browser-ready file - Shims Node.js built-in modules (path, events, stream, buffer) for browser use - Supports source maps for debugging bundled code - Applies code transforms (Babel, CoffeeScript, envify) via a plugin pipeline - Generates standalone UMD bundles for library distribution ## Architecture Overview Browserify starts from an entry file, parses its AST to find require() calls, recursively resolves each dependency from node_modules or relative paths, and concatenates everything into a single output file wrapped in a lightweight module loader. The transform system intercepts files before parsing, allowing transpilation and preprocessing. ## Self-Hosting & Configuration - Install globally or as a dev dependency for CLI or API usage - Configure transforms and plugins in the browserify field of package.json - Use watchify for incremental rebuilds during development - Generate standalone bundles with --standalone for library distribution - Pair with minifiers like uglifyify (transform) or UglifyJS (post-bundle) ## Key Features - First-class CommonJS require() support matching Node.js semantics - Shims for Node.js core modules enabling isomorphic code - Transform pipeline for preprocessing files before bundling - Plugin system for custom output handling and build orchestration - Incremental builds via watchify for fast development feedback ## Comparison with Similar Tools - **webpack** — More feature-rich bundler with code splitting, loaders, and built-in optimization; became the dominant bundler after Browserify - **Rollup** — Focuses on ES modules with tree shaking for smaller library bundles - **esbuild** — Extremely fast bundler written in Go; supports both ESM and CommonJS - **Vite** — Dev server with native ESM support and Rollup-based production builds; the current default for many frameworks ## FAQ **Q: Is Browserify still relevant?** A: Browserify is in maintenance mode. Modern projects typically use webpack, Vite, or esbuild, but Browserify remains functional for existing projects and educational purposes. **Q: How does Browserify differ from webpack?** A: Browserify focuses on CommonJS bundling with a Unix-philosophy pipeline of small transforms. webpack provides a broader feature set including code splitting, asset handling, and hot module replacement. **Q: Can Browserify handle ES modules?** A: Not natively. You can use the esmify transform to convert ES module syntax to CommonJS before bundling. **Q: What is watchify?** A: watchify is a companion tool that watches source files and incrementally rebuilds only changed modules, providing fast rebuild times during development. ## Sources - https://github.com/browserify/browserify - https://browserify.org/ --- Source: https://tokrepo.com/en/workflows/asset-7493126d Author: Script Depot