Pug: HTML template engine for Node.js
Whitespace-sensitive template engine compiling to HTML for Node.js with Haml-inspired syntax.
Learn more about Pug
Pug is a template engine that transforms indentation-based markup into HTML output. It uses whitespace and indentation to define document structure, eliminating the need for closing tags while supporting JavaScript expressions, conditionals, and loops. The engine compiles templates into JavaScript functions that can be executed with data to generate HTML. Pug is commonly used in web applications for server-side rendering, static site generation, and client-side templating.
Whitespace Syntax
Uses indentation and whitespace to define HTML structure instead of closing tags. This approach reduces markup verbosity and enforces consistent formatting.
JavaScript Integration
Supports embedded JavaScript expressions, conditionals, and loops directly within templates. Variables and functions can be passed to templates during compilation.
Modular Architecture
Built with separate packages for lexing, parsing, code generation, and runtime execution. This modular design allows for customization and integration with different build systems.
const pug = require('pug');
// Compile a template function
const template = pug.compile('p Hello #{name}!');
const html = template({ name: 'World' });
// Or render directly
const html2 = pug.render('p Hello #{name}!', { name: 'World' });
console.log(html); // <p>Hello World!</p>Validate `templateName` and `globals` are valid JavaScript identifiers to prevent possible remote code execution if un-trusted user input is passed to
- –Update pug-code-gen with the following fix: (#3438)
pug-error@2.1.0
- –Convert to TypeScript (#3355)
pug-code-gen@3.0.3
- –Validate `templateName` and `globals` are valid JavaScript identifiers to prevent possible remote code execution if un-trusted user input is passed to the compilation options (#3438)
Top in Developer Tools
Related Repositories
Discover similar tools and frameworks used by developers
nvm
Per-user Node.js version manager for switching between installed versions via command line on POSIX-compliant shells.
Floki
Elixir HTML parser with CSS selectors and multiple parser backends.
playwright
Cross-browser automation framework with built-in test runner.
redoc
React component rendering OpenAPI specifications as interactive HTML documentation.
bat
Enhanced cat replacement with syntax highlighting and Git integration for file viewing.